- Home /
Instance itself
Hi folks!!!
I'm gonna crazy with this :)
I'v a moving box (i call ti enemy) over a sphere, and when I hit it, i want generate other three cubes from the death one that moves in different directions.
So the instatiate function is inside the enemy script, and when I instantiate itself, i want to pass a different rotation for the new cubes (or cube, i'm tring with only one)
Here is my code:
var prefab : GameObject; private var death : boolean;
var script : Enemy;
var RotationAngle = 20; var tempo : float;
function Update () { transform.RotateAround (Vector3.zero, Vector3.right, Time.deltaTime); transform.RotateAround (Vector3.zero, Vector3.forward, RotationAngle * Time.deltaTime); }
function Death (death) { if (death){ Debug.Log("DEATH");
temp = Instantiate(prefab, transform.position, transform.rotation);
script.RotationAngle = 50;
temp.renderer.material.color = Color.red;
Destroy(gameObject);
}
}
In this case I'm tring to pass the RotationAngle for the new instance of the new cube, and I need to call the same script but obviously it doesn't work...:(
Any idea?
Tnx a lot :)
Answer by superlol · Mar 15, 2011 at 05:16 PM
Solved getting the script by type :)
var prefab : GameObject; var temp : GameObject; var death : boolean; var RotationAngle : float = 20;
function Update () { transform.RotateAround (Vector3.zero, Vector3.right, Time.deltaTime); transform.RotateAround (Vector3.zero, Vector3.forward, RotationAngle * Time.deltaTime); }
function Death (death) { if (death){ Debug.Log("DEATH");
temp = Instantiate(prefab, transform.position, transform.rotation);
temp.GetComponent(Enemy).RotationAngle = 50;
temp.renderer.material.color = Color.red;
Destroy(gameObject);
}
}
Answer by networkZombie · Mar 15, 2011 at 04:48 PM
this just a guess but try adding var in front of temp when you instantiate the cube.
Your answer
Follow this Question
Related Questions
Create an object and assign code to it via script? 1 Answer
Updating a variable on a script in an instanced object 1 Answer
Adding 3d items on character from inventory? 0 Answers
About refferencing other scripts 2 Answers
Is it possible to change the colour of game objects without increasing the number of draw calls? 1 Answer