Hola,Estoy tratando de modificar este script que encontré para hacer girar o rotar un objeto con el tacto. Pero lo que quiero es agregarle la función de que rote el objeto al punto de giro inicial tras una inactividad de 2 segundos.Ahora funciona la el giro pero no he logrado hacer que regrese a su punto de rotación original tras 2 segundos de inactividad. Cualquier ayuda es bienvenida!
// 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;
}
Parece ser, que ya medio funciona bien,Ahora el problema que tengo es que no me respeta los 5 segundos de pausa que le pongo para que empiece a rotar desde el ultimo toque de la pantalla.Ojala alguien me pueda ayudar.Gracias,
var rotationSpeed = 10;
var rotationStart = 0.0;
var rotatehome = false;
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;
transform.eulerAngles.y = (transform.eulerAngles.y - Input.GetAxis("Mouse X") * rotationSpeed);
Return();
rotatehome = false;
}
else if (rotatehome)
{
transform.rotation = Quaternion.RotateTowards(transform.rotation, new Quaternion(0,0,0,0.1), rotationSpeed);
}
}
function Return()
{
yield WaitForSeconds (5.0);
rotatehome = true;
}
Aquí ya encontré la solución, bueno mas bien me ayudaron, la agrego al foro por si alguien la llegase a utilizar.
var rotationSpeed = 10;
var rotationStart = 0.0;
var rotatehome = false;
var timer : float =0;
var fingeroff : boolean;
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;
transform.eulerAngles.y = (transform.eulerAngles.y - Input.GetAxis("Mouse X") * rotationSpeed);
timer = 0;
rotatehome = false;
fingeroff = false;
}else{
if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Ended)
{
fingeroff = true;
}
}
if (rotatehome)
{
transform.rotation = Quaternion.RotateTowards(transform.rotation, new Quaternion(0,0,0,0.1), rotationSpeed);
}
}
function FixedUpdate()
{
if (fingeroff ==true){
timer += 1 * Time.deltaTime;
}
if (timer >= 5){
rotatehome = true;
}
}