Hi! I have a script that chooses a random scale when an asteroid is spawned. When the asteroid is hit with a bullet, it runs a function that instantiates 4 other asteroids around it, all 1/4 its size.
I would like to know how to share the scale variable from the Awake() function with the MakeMoreThenDie() function. I believe it should be a simple task.
The script:
var Speed = 1.0;
var asteroids : GameObject[];
function Awake(){
var MinSize = 0.015;
var MaxSize = 0.4;
[COLOR="#ff0000"]var scale : float = Random.Range(MinSize,MaxSize);[/COLOR]
transform.rotation = Random.rotation;
transform.localScale = Vector3(scale,scale,scale);
}
function Update () {
transform.Translate(0,0,-Speed,Space.World);
transform.Rotate(1,1,5);
}
function OnCollisionEnter(collision : Collision){
MakeMoreThenDie(scale);
}
[COLOR="#ff0000"]function MakeMoreThenDie(foo)[/COLOR]{
var inst1pos = transform.position + transform.right - transform.up;
var inst2pos = transform.position - transform.right - transform.up;
var inst3pos = transform.position + transform.right + transform.up;
var inst4pos = transform.position - transform.right + transform.up;
var instance1 : GameObject = GameObject.Instantiate( asteroids[0],inst1pos, transform.rotation);
var instance2 : GameObject = GameObject.Instantiate( asteroids[1], inst2pos, transform.rotation);
var instance3 : GameObject = GameObject.Instantiate( asteroids[2], inst3pos, transform.rotation);
var instance4 : GameObject = GameObject.Instantiate( asteroids[3], inst4pos, transform.rotation);
foo = foo/4;
instance1.transform.localScale = Vector3(foo,foo,foo);
instance2.transform.localScale = Vector3(foo,foo,foo);
instance3.transform.localScale = Vector3(foo,foo,foo);
instance4.transform.localScale = Vector3(foo,foo,foo);
Destroy(gameObject);
}