操作キャラのスクリプトで
if (Input.GetKey(KeyCode.A))の時に回転角度に制限を付けたいのですが
書き方では制限が付かなく360°回転してしまいました...
どのようにしたらtoransform.Rotateに制限をつけれるでしょうか?
よろしくご教授のほどお願いします。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Guardian_Main : MonoBehaviour 6{ 7 Vector3 Rotate; 8 Animator animator; 9 private AudioSource sound1; 10 public GameObject fallen_guardian; 11 12 // Use this for initialization 13 void Start() 14 { 15 animator = GetComponent<Animator>(); 16 17 18 19 20 21 22 } 23 24 // Update is called once per frame 25 void Update() 26 { 27 if (Input.GetKey(KeyCode.W)) //前進 28 { 29 transform.position += transform.forward * 0.15f; 30 } 31 32 if (Input.GetKey(KeyCode.S)) //後退 33 { 34 transform.position += transform.forward * -0.09f; 35 } 36 if (Input.GetKey(KeyCode.A)) 37 { 38 transform.Rotate(0, -1.5f, 0); 39 Rotate = new Vector3((Rotate.x), Mathf.Clamp(Rotate.y,-90,90), 0); 40 } 41 if (Input.GetKey(KeyCode.D)) 42 { 43 transform.Rotate(0, 1.5f, 0); 44 } 45 46 47 } 48}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/01 15:28
2019/01/02 00:36
2019/01/03 12:16
2019/01/03 13:11
2019/01/03 13:33