前提・実現したいこと
一人称視点のゲームを作っているのですが視野角の制限の仕方がわからないです
発生している問題・エラーメッセージ
視野角が制限できず視点が一回転してしまう
該当のソースコード
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; 5using UnityEngine.SceneManagement; 6 7public class NewBehaviourScript : MonoBehaviour { 8 9 private int jumpcount = 0; 10 private bool isJump = false; 11 private GameObject char_in; 12 private Rigidbody char_rb; 13 bool pause_flag; 14 float move_x; 15 float move_z; 16 float rota_y; 17 float rota_x; 18 float mouse_x; 19 float mouse_y; 20 float tmr; 21 string test = "hey"; 22 public const int MAX_JUMP_COUNT = 1; 23 public float force = 5.0f; 24 public float jumpspeed; 25 public float gravity; 26 public float speed = 2.0f; 27 public float sensi = 2.0f; 28 public Text gameover; 29 private Text tex; 30 31 void Start() 32 { 33 char_in = GameObject.Find("Charainner"); 34 char_rb = GetComponent<Rigidbody>(); 35 pause_flag = false; 36 tex = gameover.GetComponent<Text>(); 37 } 38 39 void Update() 40 { 41 tmr = 100; 42 mouse_x = Input.GetAxis("Mouse X"); 43 mouse_y = Input.GetAxis("Mouse Y"); 44 rota_y = mouse_x * sensi; 45 rota_x = mouse_y * sensi * -1f; 46 transform.Rotate(0, rota_y, 0); 47 char_in.transform.Rotate(rota_x, 0, 0); 48 49 move_x = 0f; 50 move_z = 0f; 51 if (Input.GetKey(KeyCode.D)) 52 { 53 move_x += speed; 54 } 55 if (Input.GetKey(KeyCode.A)) 56 { 57 move_x -= speed; 58 } 59 if (Input.GetKey(KeyCode.W)) 60 { 61 move_z += speed; 62 } 63 if (Input.GetKey(KeyCode.S)) 64 { 65 move_z -= speed; 66 } 67 if (Input.GetKeyUp(KeyCode.LeftShift) /*&& speed >= 4*/) 68 { 69 speed = 2; 70 } 71 if (Input.GetButtonDown("Jump") && jumpcount < MAX_JUMP_COUNT) 72 { 73 char_rb.AddForce(Vector3.up * jumpspeed); 74 isJump = true; 75 } 76 /* 77 char_rb.velocity = move_z * transform.forward + move_x * transform.right; 78 */ 79 var move = move_z * transform.forward + move_x * transform.right; 80 char_rb.velocity = new Vector3(move.x, char_rb.velocity.y, move.z); 81 if (pause_flag) 82 { 83 Cursor.visible = true; 84 Cursor.lockState = CursorLockMode.None; 85 } 86 else 87 { 88 Cursor.visible = false; 89 Cursor.lockState = CursorLockMode.Locked; 90 } 91 if (Input.GetKey(KeyCode.Escape)) 92 { 93 pause_flag = true; 94 } 95 if(tex.isActiveAndEnabled == true) 96 { 97 speed = 0; 98 if (Input.GetKeyDown("t")) 99 { 100 SceneManager.LoadScene("title"); 101 } 102 if (Input.GetKeyDown("r")) 103 { 104 SceneManager.LoadScene("main"); 105 } 106 } 107 108 } 109 110 void FixedUpdate() 111 { 112 if (isJump) { 113 jumpcount++; 114 isJump = false; 115 } 116 } 117 118 119 void OnCollisionEnter(Collision col) 120 { 121 if(col.gameObject.tag == "Ground") 122 { 123 jumpcount = 0; 124 } 125 } 126 127 void OnCollisionStay(Collision col) 128 { 129 if (Input.GetKeyDown(KeyCode.LeftShift) && col.gameObject.tag == "Ground") 130 { 131 Debug.Log(test); 132 speed = 4; 133 } 134 } 135} 136
試したこと
単純に視野角の数値を制限するなど
自分でできる範囲で調べて試したのですができませんでした・・・
補足情報(FW/ツールのバージョンなど)
Unity 2018.2.5f.1 Personal
Visual Studio
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/23 01:21