Hi,
I am trying to modify a script I found, This script is for rotate an object and works well, but I want to add the function of return to the origin of rotation after 2 seconds of inactivity.
Please any advice is more than welcome!
Thanks
// Moves object according to finger movement on the screen
var speed : float = 0.1;
var rotationStart = 0.0;
var rotatehome = false;
var rotationSpeed = 10;
function Awake ()
{
transform.Rotate(rotationStart,0,0);
}
function Update () {
if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved) {
// Get movement of the finger since last frame
var touchDeltaPosition:Vector2 = Input.GetTouch(0).deltaPosition;
// Move object across XY plane
transform.Rotate (0,-touchDeltaPosition.x * speed, 0);
rotatehome = false;
}
else if (rotatehome)
{
transform.rotation = Quaternion.RotateTowards(transform.rotation, new Quaternion(0,0,0,0.1), rotationSpeed);
}
}
function Return()
{
yield WaitForSeconds (0.5);
rotatehome = true;
}
↧