- Home /
Instantiate issues
Hello All,
I have opened a new project of a common 2D style for pratice. However, I have been stucked on some problems, Please feel free to give help hand if possible.
This is one of the them.I have three prefabs and want to non stop rolling one by one. But I cannot..... (I drag the following script on the object which I clicked will have animation play and disappear, however, it disappeared, but no new object come out from another pre-set object.)
var panelA :GameObject; var buck : int=1; var prefabs : GameObject[]; var instance : GameObject;
function OnClick(){ animation.Play(); Scoreboard.Score = Scoreboard.Score + buck; panelA.active=false; instance.Instantiate(prefabs[Random.Range(0,prefabs.length)]); Debug.Log("clicked"); }
Can anyone please give some hints or direction, is there a way that the prefab can be re-use( brand new ) after used once? Cuz you can see on the script, Animation of the object was played, I tried animation.Rewind(), but there is no reaction at all.
I am not lazy guy, I have really checked and try much before asking question,as I am very new in code, so PLEASE give a help hand, thx.
Yan
Answer by mohitramani · Jun 01, 2013 at 08:54 AM
to instantiate
instance = Instantiate(prefabs[Random.Range(0,prefabs.length)]);
To play the animation in reverse order:
gameObject.animation["animation name"].speed = -1; // speed = 1 for playing in normal order gameObject.animation["animation name"].Play();
To start animation from specific time(may b beginning) gameObject.animation["animation name"].time = 0.0; // for beginning or any other float value gameObject.animation["animation name"].Play();
Hope it helps...
Thank You mohitramani,
animation. play() is not mess after settled the instantiate problem by your guide. It will be a brand new object when instantiate.
Your welcome, you should close this question now. Accept the answer and close the question.
Your answer
Follow this Question
Related Questions
instantiate random prefabs based on player camera distance 1 Answer
Random.Range not working. 1 Answer
How to randomly generate prefab? 2 Answers
Randomizing a selection from an array 1 Answer
Item Drops on enemy spawn and death? 2 Answers