var type : int;
var speed = 10;
var rotateSpeed = 5;
function Start () {
type = Random.Range(1,3);
}
function Update () {
if(type == 1){
rigidbody.AddForce (Vector3.right * -speed);
}
if(type == 2){
transform.Rotate(0,0,rotateSpeed);
rigidbody.AddForce (Vector3.right * -speed);
}
else{
Debug.Log ("Hello");
transform.rotation.z += 90;
rigidbody.AddForce (Vector3.right * -speed);
}
}
Works great. Just that when “type” equals 3, the rotation does not to change to 90. the odd thing is that the rest of else statement works fine. As you can see I added a Debug.Log and i can verify that type 3 does show up.
“type” will never equal 3; see the docs for Random.Range. Also your if logic could be improved; it should be if/else if/else. Or better yet, switch/case instead. Anyway, transform.rotation is a 4D quaternion, and the x/y/z/w axes do not directly correspond to 3D eulerAngles axes, nor do they use degrees. See the docs for quaternions and transform.rotation.
It cannot be 3, not with the code you posted. Random.Range(1, 3) will only ever return 1 or 2; that’s how Random.Range works with integers. See the docs.