Im working on a game where I have a series of objects spawn in a grid pattern. I have an array setup that randomly picks spawn points and objects to spawn. My problem is that when I try to spawn a cube object it immediately has velocity and floats away. The objects need to stay put until interacted with. I tested other objects and spheres spawn just fine with no movement till they are clicked on.
The spawned objects only have this scripting for the time being. I was thinking of adding a line to freeze movement till clicked, but was curious why they would spawn that way to begin with.
private var timer : float = 0.0;
static var clicked : boolean = false;
private var fadeaway : float = 0.0;
static var deltaTime : float;
function start(){
timer += Time.deltaTime;
}
function OnMouseDown(){
//Debug.Log("you clikced me");
this.renderer.material.color = Color.red;
this.transform.Rotate(Vector3(45,0,0));
this.transform.localScale.x = 0.75 * this.transform.localScale.y;
clicked = true;
/* if the thing you click has rigidbody then you could make it start spinning or moving:
this.rigidbody.AddRelativeTorque (4, 10, 0); */
/* We can control other objects! suppose there is another cube called "cube2":
var othercube = GameObject.Find("Cube2");
othercube.renderer.material.color = Color.yellow;
othercube.transform.Translate(0, 1, 0); */
}
function Update () {
if(clicked == true){
Debug.Log("clicked me");
fadeaway += Time.deltaTime;
}
if(fadeaway >= 1){
rigidbody.AddRelativeTorque (0, -1.0 * 100 * Time.deltaTime, 0);
rigidbody.velocity = transform.TransformDirection(Vector3(0,10, 10));
}
if(fadeaway >= 5){
this.renderer.enabled = false;
Debug.Log("bye bye");
}
}