【Unity】Input System(Generate C#)をInput.GetKeyDownのように使う方法を教えてください。
Input System(Generate C#)をInput.GetKeyDownのように使う方法を教えてください。
一応コードを載せておきます。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5namespace Nissy64 { 6 public class PlayerCombat : MonoBehaviour { 7 [Header("Attack")] 8 public Transform attackPoint; 9 public LayerMask enemyLayer; 10 public float attackRange = 1; 11 public int attackDamage = 40; 12 13 private MyInput myInput; 14 private bool fireInput; 15 16 void Awake() { 17 myInput = new MyInput(); 18 myInput.Enable(); 19 } 20 21 void Update() { 22 MyInputs(); 23 } 24 25 void FixedUpdate() { 26 if(fireInput) { 27 Attack(); 28 } 29 } 30 31 private void MyInputs() { 32 fireInput = myInput.Play.Fire.ReadValue<float>() > 0.01f; 33 } 34 35 private void Attack() { 36 Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, enemyLayer); 37 38 foreach(Collider2D enemy in hitEnemies) { 39 enemy.GetComponent<Enemy>().TakeDamage(attackDamage); 40 } 41 } 42 43 void OnDrawGizmosSelected() { 44 if(attackPoint == null) { 45 return; 46 } 47 Gizmos.DrawWireSphere(attackPoint.position, attackRange); 48 } 49 } 50}
補足情報(OS:Windows10/Unity 2021.3.9f1)
出来るだけ早めにお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/09/10 08:40
2022/09/10 10:30
2022/09/10 12:18
2022/09/11 06:36