I'm trying to make an empty gameObject spawn projectiles, called "RedCube". I noticed that instead of cloning the original prefab, the code keeps cloning the last spawned cube. So, when all the cubes despawn, the spawner won't work anymore.
Here's the code. It's supposed to spawn the cubes on the mouse click, launch them at speed, and destroy them after a second.
#pragma strict
var RedCube : Rigidbody;
var speed = 1;
function Update () {
if (Input.GetMouseButton(0)){
RedCube = Instantiate(RedCube, transform.position, transform.rotation);
RedCube.velocity = transform.TransformDirection(Vector3(speed, 0, 0));
Destroy(RedCube.gameObject, 1);
}
}
Also, here's a screenshot of the hierarchy. So many clones of clones of clones etc...
![alt text][1]
[1]: /storage/temp/61430-unity-bug.jpg
EDIT: Turns out the repeated cloning also makes the game run slower after about 10 seconds
↧