タイトルの通りです。あと初心者です。
今回、RigidbodyとInputSystemを使った自機の移動を作りました、その中で移動している自機に慣性が乗っているのでそれを消すためにボタンが離された時、という処理をスクリプトで実行したいんですけど方法が全くわかりません。
今回欲しい内容として、InputSystemで押したとき、離した時をどうやって実行するかです。(このスクリプトの場合だと、OnMoveが離された後ですね)
調べたこと、
https://gamedev65535.com/entry/unity_inputsystem_interaction/
https://logmi.jp/tech/articles/326468
https://gamedev65535.com/entry/unity_inputsystem_interaction_longpressedrapidfire/
以下上から、 OnEnable内のinput.actions[""].performed までは分かる、そのあとに何故+=があるのか?そもそもなぜ足しているのか?
コールバックを調べてもよくわからなかった。
contextを調べてもよくわからなかった、public void Process(ref InputInteractionContext context)この引数の意味も。
C#
1コード 2using System.Collections; 3using System.Collections.Generic; 4using UnityEngine; 5using UnityEngine.InputSystem; 6 7[RequireComponent(typeof(PlayerInput))] 8public class InputSystemTest : MonoBehaviour 9{ 10 private Rigidbody rb; 11 private InputAction moveAction, jumpAction; //_これ(アンダーヴァー)を識別で着けたりする。unity道場では突けてる 12 public float Speed = 500; //スピードを1.0とインスペクター上で仮定して 13 14 private void Awake() 15 { 16 var input = GetComponent<PlayerInput>(); 17 var actionMap = input.currentActionMap; 18 rb = GetComponent<Rigidbody>(); 19 20 moveAction = actionMap["Move"]; 21 jumpAction = actionMap["Jump"]; 22 23 } 24 25 26 27 28 void OnMove() 29 { 30 var move = moveAction.ReadValue<Vector2>(); 31 32 33 34 if (move.x > 0) 35 { 36 rb.AddForce(new Vector3(Speed, 0.0f, 0.0f)); 37 } 38 39 if (move.x < 0) 40 { 41 rb.AddForce(new Vector3(-Speed, 0.0f, 0.0f)); 42 } 43 44 if (move.y > 0) 45 { 46 rb.AddForce(new Vector3(0.0f, 0.0f, Speed)); 47 } 48 49 if (move.y < 0) 50 { 51 rb.AddForce(new Vector3(0.0f, 0.0f, -Speed)); 52 } 53 } 54 55 void Onjump() 56 { 57 var jump = jumpAction.triggered; 58 59 if (jump) 60 { 61 rb.AddForce(new Vector3(0.0f, 200.0f, 0.0f)); 62 Debug.Log("aa"); 63 } 64 } 65 66 67 68 69 // Start is called before the first frame update 70 void Start() 71 { 72 73 } 74 75 // Update is called once per frame 76 void FixedUpdate() 77 { 78 OnMove(); 79 80 Onjump(); 81 } 82 83} 84
回答1件
あなたの回答
tips
プレビュー