1

我想旋转盒子每个按键(左右)!

public class BoxFlipper : MonoBehaviour { 

   private Vector3 newRotation;

   void Update () {
             Button();
   }

   private void Button () {
             if (Input.GetKeyDown(KeyCode.Right))
                       FlipRight();
              if (Input.GetKeyDown(KeyCode.Left))
                       FlipLeft();
   }

   private void FlipRight () {
        newRotation = new vector3 (0,0,90);
        transform.rotation= Quaternion.Slerp(transform.rotation, newRotation.rotation, .05f);  
   }

   private void FlipLeft () {
        newRotation = new vector3 (0,0,-90);
        transform.rotation= Quaternion.Slerp(transform.rotation, newRotation.rotation, .05f);  
   }

}
4

0 回答 0