- Home /
 
               Question by 
               CubePhysics · Mar 15, 2014 at 06:24 PM · 
                c#animationrotationtransform  
              
 
              How do i rotate an object "Once"
my script turns the object 90 degrees everytime i press 'd'(so if i press if 4 times it will turn the object the whole way round and back). I only want it to go the 90 degrees rotation whenever its on a different degrees for example when its facing the left (270 degrees) i want it to go to 90 degrees. How would i do that. Here is my code
 using UnityEngine;
 using System.Collections;
 
 public class Animation : MonoBehaviour {
 
     // Use this for initialization
     void Start () 
     {
         animation.Play("Standing");
         animation["StandToRun"].speed = 1f;
         animation["RunToStand"].speed = 1f;
         animation["Jump"].speed = 1f;
     }
     
     // Update is called once per frame
     void Update () 
     {
         if(Input.GetKeyDown(KeyCode.W))
         {
             animation.CrossFade("Run");
         }
         if(Input.GetKeyUp(KeyCode.W))
         {
             animation.CrossFade("Standing");
         }
         if(Input.GetKeyDown(KeyCode.D))
         {
             animation.CrossFade("Run");
             transform.Rotate(0,90,0);
         }
         if(Input.GetKeyUp(KeyCode.D))
         {
             animation.CrossFade("Standing");
         }
         if(Input.GetKeyDown(KeyCode.A))
         {
             animation.CrossFade("Run");
         }
         if(Input.GetKeyUp(KeyCode.A))
         {
             animation.CrossFade("Standing");
         }
         if(Input.GetKeyDown(KeyCode.S))
         {
             animation.CrossFade("Run");
         }
         if(Input.GetKeyUp(KeyCode.S))
         {
             animation.CrossFade("Standing");
         }
 
 
         if(Input.GetKeyDown(KeyCode.Space))
         {
             animation.CrossFade("Jump");
         }
 
 
     }
 }
 
               Comment
              
 
               
              Answer by MrSpoke · Mar 15, 2014 at 07:29 PM
If you use transform.Rotate, it will rotate your object 90 degrees on its own axis. Try storing the rotation value in a temporary variable and changing it then.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                