[英]Unity's new Input Settings how to simulate an analog stick using keys
我試圖僅在 Unity 的新設置 package 中使用鍵來模擬模擬搖桿。 到目前為止,這是我的代碼,它幾乎可以工作,除了 Vector2.zero 導致初始值不正確,因為以下條件使用這些值進行平均。
當按下適當的按鈕組合時,我想將input
設置為 NW、SE 等方向。 此外,當僅按下一個按鈕時,應正確設置基本方向。
有這個,但我無法使它工作:
Vector2 input;
input = Vector2.zero;
if (_Keyboard.aKey.isPressed) input = (input + Vector2.left).normalized;
if (_Keyboard.dKey.isPressed) input = (input + Vector2.right).normalized;
if (_Keyboard.wKey.isPressed) input = (input + Vector2.up).normalized;
if (_Keyboard.sKey.isPressed) input = (input + Vector2.down).normalized;
在這個視頻中找到了答案。
請參閱下面的修改代碼:
input = new Vector2();
if (_Keyboard.aKey.isPressed) input.x -= 1;
if (_Keyboard.dKey.isPressed) input.x += 1;
if (_Keyboard.wKey.isPressed) input.y += 1;
if (_Keyboard.sKey.isPressed) input.y -= 1;
input.Normalize();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.