- Home /
 
Object won't rotate z axis on second click?
HI! The script below only works on the initial tap, but when I click a few times, normally, between 5 and 9 it will stop rotating the object on its z axis and won't rotate it back when I click. I can't figure out why cause Ive done this before but for some reason it won't do this for my sprite? The yield is so that it will wait a few seconds before rotating back. Thanks!
 #pragma strict
 
 var rotationUp = 0.0f;
 var rotationDown = 0.0f;
 var rotationDownDelay = 0.0f;
 var jumpSound : AudioSource;
 function Update () {
         
         if (Input.GetButtonDown("Fire1")) {
 
             rigidbody2D.velocity = Vector2(0.0f, 7.0f);
             jumpSound.Play();
             gameObject.transform.rotation.z = rotationUp;
 
         }else{
             LookDown();
         }
         
 }
 
 function LookDown () {
     
     yield WaitForSeconds (2);
     gameObject.transform.rotation.z = rotationDown;
     
 }
 
              Answer by FreeTimeDev · Mar 02, 2014 at 07:38 PM
From the Script Reference page of transform.rotation:
Unity stores rotations as Quaternions internally. To rotate an object, use Transform.Rotate. Use Transform.eulerAngles for setting the rotation as euler angles.
I understand but in this case that really doesn't do anything cause as far as I know thats just another way to do rotation which isn't my problem? $$anonymous$$y problem is it won't rotate consistently
Ive been testing it and I found that it will only respond to the first click and then after how many seconds thats in the LookDown function it will stop
Answer by Vardan Meliksetyan · Mar 02, 2014 at 07:42 PM
You use wrong !
I am writing C# code and you convert in javascript code ok!
using UnityEngine; using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () 
 {
     StartCoroutine( YourWaitFunction( 5.0f ));
 }
 IEnumerator YourWaitFunction( float time)
 {
     yield return new WaitForSeconds(time); 
 }
 
               }
Ive been testing it and I found that it will only respond to the first click and then after how many seconds thats in the LookDown function it will stop
Your answer