Friday, February 24, 2017

unity - Display image a couple seconds after an enemy spawns?


So right now I have enemies that spawn behind objects with a delay.


What I need is to display an image on the screen 5 seconds after each enemy spawns (it's to show the player it has been "attacked") and that image has to disappear after like 2 seconds so.



I know I have to use WaitForSeconds but I don't know how because everything I've tried isn't working.


Here's my code:


 public class TimedSpawn : MonoBehaviour {

public GameObject spawnee;
public bool stopSpawning;
public float spawnTime;
public float spawnDelay;

// Use this for initialization

void Start () {
InvokeRepeating ("SpawnObject", spawnTime, spawnDelay);
}

public void SpawnObject (){
Instantiate (spawnee, transform.position, transform.rotation);

if (stopSpawning) {
CancelInvoke ("SpawnObject");
}

}
}


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...