- Home /
Plant Reproduction, Instantiate problem
Hi everyone ! I am learning Unity and Javascript since 3 days now and I need your help for something.
I decided to practice all of what I learned by making a "plant" in unity, that would grow, change model, reproduce and die. For the growing, changing model and dying part everything works find, but I can't seem to make it reproduce.
When I instantiate a new plant from the original one, that new plant is as old as the original one. Any way I can solve this ?
var Vie : float = 60;
var Adult : float =40;
var Dead : float =20;
var Reproduction : boolean = true;
var Plant : GameObject;
function Update () {
Vie -= Time.deltaTime;
if(Vie<=0){ Destroy(gameObject);
}else if(Vie<=Adult){
var Fstep : MeshRenderer = gameObject.Find("PlantYoung").GetComponent(MeshRenderer); Fstep.enabled = false;
var Sstep : MeshRenderer = gameObject.Find("PlantAdult").GetComponent(MeshRenderer); Sstep.enabled = true;
}
if((Vie<=Adult) && (Reproduction)){ var position = Vector3(Random.Range(-10,10), 0, Random.Range (-10, 10)); Instantiate (Plant, position, Quaternion.identity); Reproduction = false;
}
if(Vie<=Dead){ Sstep.enabled = false;
var Tstep : MeshRenderer = gameObject.Find("PlantDead").GetComponent(MeshRenderer); Tstep.enabled = true;
}
}
Is this all the code you are using? Post the rest if there's more.
Also, can you format your code correctly by using the button with the binary (0's and 1's) image on it.
Answer by MannyLectro · Dec 04, 2012 at 12:51 PM
Hi ! Thanks Rob ! But doing that only help for the first generation of plant, but then the next one is the prefab, and I get the same problem again.
Please use the "add new comment" button for comments. :(
Your answer
Follow this Question
Related Questions
Instantiate: Create Connection 1 Answer
Instantiated gameObjects can't find each other 0 Answers
Done Something Wrong, Don't Know What I've Done? 2 Answers
OnTriggerStay Instantiate Problem (just want a single spawn, but there are multiple) 1 Answer
Client/Server Network Instantiate Problems/Client Can't Connect 0 Answers