I am working on a temple run style game.How do i instantiate an object after some time ?
I have made a function and used yield…and no success
.
And what I get is many unlimited number of objects get instantiated.
Please Help I am new to Unity.
1 Answer
1Hey this should help you: I hope this is the effect you were trying to get
// The object to be Instantiated
public var object : GameObject;
// Time before first Instantiate
public var firstInstantiate : float = 2;
//Set repeatRate to 0 if you only want to create 1 object
public var repeatRate : float = 2;
function Start () {
InvokeRepeating("Instantiate", firstInstantiate , repeatRate);
}
function Instantiate () {
Instantiate (object, Vector3(0, 0, 0), Quaternion.identity);
}
One easy way is [InvokeRepeating()][1]. [1]: http://docs.unity3d.com/Documentation/ScriptReference/30_search.html?q=invokerepeating
– robertbuPaste your coroutine/yield code.
– whydoidoit