How to make enemy (with custom texture/material) flash when hit in Unity3d


Joined
Nov 25, 2020
Messages
5
Reaction score
0
Hi, I was wondering how to make an enemy flash when hit in unity3d. My enemies, though, have a custom texture (an image) and I'm not sure if the solutions on the internet which use IEnumerators and coroutines and stuff would work on such gameobjects. Can someone please help? thanks.
 
Ad

Advertisements

Joined
Mar 3, 2021
Messages
46
Reaction score
9
Coroutines work just fine on GameObjects and they're used very frequently. I've read that many games have very little code in the Update functions as all the animation/etc code is done via coroutines. I'd spawn a coroutine, change or toggle the material of the object, and have the coroutine increment a counter, sleep, and then yield. When the counter hits a certain value, stop yielding and the coroutine will exit. One of the first tutorials I did suggested using coroutines for anything that has a defined stop condition. Anything that needs to sleep will also need to be in a coroutine. They're very handy, get used to them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top