- Home /
Input Help!
Im new at Unity and ive created a side on 2d game where a car goes at a constant speed (normally) and the user controls the rotation on the Z axis - ie tilt the car as it goes over ramps etc. Ive used the following script but im obviously going wrong as im not sure how to make the control make the car rotate, any edits to the script from the pros would be much appreciated!
function Update () { if(Input.GetAxis("Horizontal")){ Transform.Rotate(Vector3(0,0,1)); } }
Answer by Berenger · Jan 27, 2012 at 12:53 AM
That function is modifying the math behind the Transform. The problem is that you're calling it directly from the class, not from an instance of the class. So you need the Transform component of your object, and you Unity being a good guy you can do that easily :
function Update(){
if( Input.GetAxis("Horizontal") ){
transform.Rotate(Vector3(0,0,1));
}
}
Not that different isn't it ? the important part is transform instead of Transform. If the object still don't rotate correctly, check your axis, or change the z on the rotation.