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 :)

this just a guess but try adding var in front of temp when you instantiate the cube.

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);
        }
}