right now in my game, four enemies spawn in four spawn points with a delay, but what I want to do is that if you don't kill the enemy after a couple seconds, an animation (it's an animation of a scratch, basically to let the player know it has been attacked) appears.
Right now I have a script that display an image (it's an image because I was testing the scripts), but now I want to change the image for the animation but after trying and failing a lot of times I decided to ask here, and hopefully someone can help me.
This is the script of the "attack", and it's attached to the enemy prefab:
public Image TargetImage; void Start () { TargetImage.enabled = false; } public void spawnAttack(){ StartCoroutine (playerIsAttacked (5, TargetImage)); } public IEnumerator playerIsAttacked (float t, Image im) { yield return new WaitForSeconds (t); TargetImage.enabled = true; } } and this is in the timed spawn script:
public class TimedSpawn : MonoBehaviour { public GameObject spawnee; public bool stopSpawning; public float spawnTime; public float spawnDelay; void Start () { InvokeRepeating ("SpawnObject", spawnTime, spawnDelay); } public void SpawnObject (){ GameObject newSpawn = Instantiate (spawnee, transform.position, transform.rotation) as GameObject; newSpawn.GetComponent <enemyAttack> ().spawnAttack (); if (stopSpawning) { CancelInvoke ("SpawnObject"); } } }