- Home /
How to let clone reborn?
I use clone to duplicate in one of game's stage. I succeeded.
As below is random clone code:
(1)Create a script is call "A.js" and write a global variable to count the number of generated objects like this:
static var objectCount_coin:int=0;
(2) Create another script is call "B.js" and write this:
var coinUp:GameObject;//set these in the inspector
var coinFlat:GameObject;//set these in the inspector
var coinLeft:GameObject;//set these in the inspector
var coinRight:GameObject;//set these in the inspector
var haveAnObject_coin:boolean=false;
function Update()
{
if
(globalCount_coin.objectCount_coin<10&& !haveAnObject_coin)
{
var rand_coin=Random.Range(0,100); //to see if we should create an object
if(rand_coin>50)
{
haveAnObject_coin=true;
globalCount_coin.objectCount_coin +=1;
rand_coin=Random.Range(0,100); //to see if we should make a cube or sphere
if(rand_coin<=25)
Instantiate (coinUp, transform.position, transform.rotation);
if(rand_coin<=50 && rand_coin>25)
Instantiate (coinFlat, transform.position, transform.rotation);
if(rand_coin<=75 && rand_coin>50)
Instantiate (coinLeft, transform.position, transform.rotation);
if(rand_coin<=100 && rand_coin>75)
Instantiate (coinRight, transform.position, transform.rotation);
}
}
}
(3) Put "B.js" into 30 empty objects.
Thus will show 10 clones in 30 random empty objects.
And now, my problem is: I leave the stage, and enter the stage again, How to let clone random reborn?
How to delete last play of the clone and reborn the new clone?
Thanks a lot :)
Your answer
Follow this Question
Related Questions
How to instantiate from prefab, not from instance? 3 Answers
Sometimes one sometimes two clone is formed. I just want to form a clone 1 Answer
Pass a copy of a GameObject as variable to another script? 1 Answer
How to have different textures for cloned gameobject (instantiated) 1 Answer
How to delete instantiated GameObject 4 Answers