So ... I have this script:
var Plant : Transform;
function Update(){
var
AddPlant=Instantiate(Plant,transform.Find("Seed").transform.position,Quaternion.identity);
}
This means that I instantiate every second a "Plant".
But how can I instantiate a "Plant" one time without changing the function?
Albert
September 6, 2010, 3:51pm
2
instantiate on user input
var Plant : Transform;
function Update()
{
if(Input.GetKeyDown("e"))
{
var AddPlant=Instantiate(Plant,transform.Find("Seed").transform.position,Quaternion.identity);
}
}
An easy way would be to create a boolean.
var Plant : Transform;
var isInstantiated : boolean = false;
function Update(){
if(!isInstantiated)
{
isInstantiated = true;
var AddPlant=Instantiate(Plant,transform.Find("Seed").transform.position,Quaternion.identity);
}
}
Ok, I made it like this :
var grow : boolean = false;
var Plant : Transform;
function Update(){
if (.....){
grow = true;
if(grow){
Invoke("Growing", 2);
}
function Growing(){
var AddPlant = Instantiate(Plant, transform.Find ("Seed").transform.position, Quaternion.identity);
Debug.Log("Planting");
}