Hi
I have a variable count that keeps count of the objects i am creating and giving them a name based on it.
There is a small bug somewhere that makes it keep the last number it had from the last run of the script, alas it don't reset to 0;
var rate : float=0.0;
var spawn : GameObject;
var cube : GameObject;
var count : int = 0;
var position : Vector3;
var text1="Press H for instructions.";
var text2="Left mousebutton = Generate cubes";
var text = text1;
function Awake() {
count=0;
Debug.Log(count);
}
function Update () {
if (Input.GetButton("Fire1") && Time.time > rate) {
position=spawn.transform.position;
// check to see if spawnpoint is outside the room
if (position.z <100 && position.z > -96){
if (position.x <100 && position.x>-100){
++count;
Instantiate (cube,position,Quaternion.identity);
rate=0.25;
count=count+1;
cube.name=count.ToString();
}
}
}
}