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
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
#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);