- Home /
Question by
delfinatarga · Nov 02, 2017 at 01:15 AM ·
imagespawnwaitforseconds
Display image a couple seconds after an enemy spawns?
Hello! 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 yeah i know i have to use WaitForSeconds but clearly 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");
}
}
}
Comment