前提
ブロック崩しを制作しています。
上下矢印キーに左右移動を割り当てたいのですが、うまくいかず困っています。
実現したいこと
- ↑キー…プレイヤー(バー)を右に移動
- ↓キー…プレイヤー(バー)を左に移動
該当のソースコード
C#
1 public float speed = 10f; 2 Rigidbody myRigidbody; 3 4 void Start() 5 { 6 myRigidbody = GetComponent<Rigidbody>(); 7 } 8 9 // Update is called once per frame 10 void Update() 11 { 12 13 myRigidbody.velocity = new Vector3(GetKey(KeyCode.UpArrow) * speed,0f,0f); 14 myRigidbody.velocity = new Vector3(GetKey(KeyCode.DownArrow) * speed,0f,0f); 15 16}
試したこと
myRigidbody.velocity = new Vector3(Input.GetAxis("Horizontal") * speed,0f,0f);
参考にした左右の割り当てが上記だったので分けたらいいか?と思ったが
Assets\Player2.cs(20,44): error CS0103: The name 'GetKey' does not exist in the current context
とエラーが出てしまう。
補足情報(FW/ツールのバージョンなど)
Unity 2021.3.4f1
visualstudio
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/08/30 02:53