- Home /
Question by
user-8379 (yahoo) · Jan 21, 2011 at 10:37 PM ·
animationgameobjectrotatecontrol
Control the Animation
I animated a Plane Gameobject to rotate on the x-axis. I want to make a script that if I push the button the Plane would rotate one time around. I'm not that good with javascripting. Can anyone help me out.
Thanks
Comment
Answer by Jessy · Jan 21, 2011 at 11:25 PM
#pragma strict
var degreesPerSecond : float;
function Update () { if (Input.GetButtonDown("Jump")) StartCoroutine(Spin()); }
function Spin () { enabled = false; var originalRotation = transform.rotation; var degreesRotated = 0F; while (true) { var degrees = degreesPerSecond * Time.deltaTime; if (degreesRotated > 360 - degrees) break;
transform.RotateAround(transform.position, Vector3.right, degrees);
degreesRotated += degrees;
yield;
}
transform.rotation = originalRotation;
enabled = true;
}
Change degrees to be negative in this line, if you want it to rotate in the opposite direction:
transform.RotateAround(transform.position, Vector3.right, -degrees);