- Home /
Question by
r3voluti0n · Jul 12, 2013 at 07:55 AM ·
gameobjecttimesecondsinstantiat
Instantiating object after some fixed time...
How can i instantiate a gameobject 3 seconds after one of the objects is destroyed???
Comment
Answer by JohnnySunshine · Jul 12, 2013 at 09:21 AM
Invoke will call a function after waiting for some time.
void Start()
{
Invoke("CreateMyInstance", 3.0f);
}
// Will be called 3 seconds after level start
void CreateMyInstance()
{
Instantiate(prefab, Vector3.zero, Quaternion.identity);
}
sir I'm trying to create unlimited time what can i do ans plz
Answer by SinisterRainbow · Jul 12, 2013 at 08:14 AM
Resources.Load() or do not destroy the object, HIDE it instead then flip it back on somewhere else. Delay code in C# :
//Javascript requires something different ..
// read on IEnumerators if you don't understand.
public IEnumerator DoDelay(float seconds, System.Action callback) {
yield return new WaitForSeconds(seconds);
callback();
}
public void MyCallBack() {
//this gets called when DoDelay is ready. can instantiate here or whatever.
}
void StartDelay() { //call this in your calling function...
StartCoroutine(DoDelay(3.0f,MyCallBack));
}
Thanks for replying but the problem lies within the raycast i.e i shoot a ray and check whether it hit the object or not and if it hit it then delete that object and instantiate it after 3 seconds