Hi guys…i am working on a 2D shooting game in which enemy gets destroyed after getting hit by a bullet and then reappears after 2 sec at some random position on x-axis.
my code is :
using UnityEngine;
using System.Collections;
public class collision : MonoBehaviour {
IEnumerator OnCollisionEnter (Collision objectCollided)
{
if (objectCollided.gameObject.name == "enemy")
{
Destroy(this.gameObject); // to destroy bullet
objectCollided.gameObject.renderer.enabled = false;
yield return new WaitForSeconds(2);
GameObject.Find("enemy").transform.position = new
Vector3(Random.Range(9.0f,23.0f),3.5f,0);
objectCollided.gameObject.renderer.enabled = true;
}
}
}
The problem is that enemy disappears but does not reappear anywhere. If i use void instead of IEnumerator and delete yield statement, then it works fine but then there is no time delay.
Please advice me how to do this.