I want to smothly rotate an object to a specific location so I coded this:
#pragma strict
var turnSpeed : float = 80;
var left = 55.0;
var right = 130.0;
var center = transform.rotation;
function Update () {
var rot = transform.rotation.eulerAngles.y;
//rotate the object left.
if(Input.GetKey("a") && rot >= left)
transform.Rotate(Vector3.forward, -turnSpeed * Time.deltaTime);
//rotate the object right.
else if(Input.GetKey("d") && rot <= right)
transform.Rotate(Vector3.forward, turnSpeed * Time.deltaTime);
//brink the object back to its starting possition... Or at least that's what I want it to do!
else {
transform.rotation = Quaternion.Lerp(transform.rotation, center, turnSpeed * Time.deltaTime);
}
}
I get this error “You are not allowed to call this function when declaring a variable. Move it to the line after without a variable declaration.”
And when I go to play mode I get a couple more errors!
Any help?