ゲーム内容ですが 岩をクリックして岩に当たると自動で攻撃モーションが走り岩が消えると待機モーションに戻りたいのですが
提示コードのコメント部内部のコードですがvoid AttackExit();関数でオブジェクトが消えて当たり判定を抜けた時にisAttack = false;として
攻撃モーションをキャンセルしたいのですが。void AttackExit();関数が実行されません。これはどうしてでしょうか?
またこれを実装するにはUnityのどういった機能を使うべきなのでしょうか?
cs
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Rock : StageObject 6{ 7 public GameObject item; 8 public bool isDelete; 9 void Start() 10 { 11 isDelete = false; 12 } 13 14 void Update() 15 { 16 if (HP < 0) 17 { 18 19 //Instantiate(item, transform.position, transform.rotation); 20 21 Destroy(this.gameObject); 22 isDelete = true; 23 } 24 } 25 26 27 private void OnTriggerEnter(Collider other) 28 { 29 30 if (other.gameObject.tag == "Weapon") 31 { 32 HP--; 33 } 34 35 36 37 } 38 39 40} 41
cs
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class MoveControl : MonoBehaviour 6{ 7 8 // ############################## コンポーネント ############################## 9 private Rigidbody rb; //Rigidbody 10 private Animator anim; //Animator 11 12 // ############################## 移動 ############################## 13 public Vector3 movePosition; //移動座標 14 private Vector3 movePrevPosition; //前の移動座標 15 public Vector3 moveVector; //移動方向 16 public float moveSpeed; //移動速度 17 18 // ############################## GameObject ############################## 19 20 //武器 21 public GameObject weapon; //ゲームオブジェクト 22 private Weapon weaponScript; //スクリプト 23 24 // ############################## 判定 ############################## 25 private bool isAttack; 26 public bool isMove; 27 28 void Start() 29 { 30 anim = GetComponent<Animator>(); //Animator 31 rb = GetComponent<Rigidbody>(); //Rigidbody 32 33 movePosition = new Vector3(0,0,0); //移動座標 34 moveVector = new Vector3(0,0,0); //移動方向 35 moveSpeed = 0; //移動速度 36 37 weaponScript = weapon.GetComponent<Weapon>(); //武器 38 39 40 isAttack = false; 41 isMove = false; 42 } 43 44 void FixedUpdate() 45 { 46 rb.velocity = moveVector.normalized * moveSpeed; 47 } 48 49 50 private void Attack() 51 { 52 53 } 54 55 56 private void Motion() 57 { 58 anim.SetFloat("move", (float)rb.velocity.magnitude); 59 anim.SetBool("isAttack", isAttack); 60 61 } 62 63 64 65 private void Move() 66 { 67 68 if (isMove == true) 69 { 70 //移動方向 取得 71 moveVector = movePosition - transform.position; 72 moveVector.y = 0; 73 74 moveSpeed = 10; 75 //向きを変える 76 Quaternion look = Quaternion.LookRotation(moveVector, Vector3.up); 77 transform.localRotation = look; 78 79 isMove = false; 80 } 81 82 } 83 84 85 GameObject g; 86 87 void Update() 88 { 89 90 Debug.Log(isAttack); 91 92 93 //Debug.Log(rb.velocity.magnitude); 94 95 96 Motion(); //モーション 97 Attack(); //攻撃 98 Move(); //移動 99 } 100 101 102 103 104 private void OnCollisionEnter(Collision other) 105 { 106 if (other.gameObject.tag == "AttackArea") 107 { 108 109 moveSpeed = 0; 110 moveVector = new Vector3(0, 0, 0); 111 rb.velocity = new Vector3(0, 0, 0); 112 } 113 114 //Reach 115 if (other.gameObject.tag == "Reach") 116 { 117 moveSpeed = 0; 118 moveVector = new Vector3(0, 0, 0); 119 rb.velocity = new Vector3(0, 0, 0); 120 } 121 } 122 123 private void OnCollisionStay(Collision other) 124 { 125 126 if (other.gameObject.tag == "AttackArea") 127 { 128 129 } 130 131 } 132 133 private void OnCollisionExit(Collision other) 134 { 135 //Debug.Log("ssssss"); 136 //isAttack = false; 137 } 138 139 140 private void OnTriggerEnter(Collider other) 141 { 142 143 } 144 145 /////////////////////////////////////////////////////////////////////////////////// 146 //子のAttackCol 147 public void AttackStay(Collider other) 148 { 149 if(other.gameObject.tag == "AttackArea") 150 { 151 isAttack = true; 152 } 153 } 154 155 //子のAttackCol 156 public void AttackExit(Collider other) 157 { 158 Debug.Log("ああああ"); 159 if (other.gameObject.tag == "AttackArea") 160 { 161 } 162 isAttack = false; 163 164 } 165///////////////////////////////////////////////////////////////////////////////////// 166 //イベント処理 167 public void AttackStart() 168 { 169 //Debug.Log("Attack Start "); 170 weaponScript.collider.enabled = true; 171 } 172 173 public void AttackEnd() 174 { 175 //Debug.Log("Attack End "); 176 177 weaponScript.collider.enabled = false; 178 } 179} 180
あなたの回答
tips
プレビュー