質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

オブジェクト

オブジェクト指向において、データとメソッドの集合をオブジェクト(Object)と呼びます。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

0回答

2062閲覧

[Unity] オブジェクトが消えた時を認識させいたい

退会済みユーザー

退会済みユーザー

総合スコア0

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

オブジェクト

オブジェクト指向において、データとメソッドの集合をオブジェクト(Object)と呼びます。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

0クリップ

投稿2021/07/12 02:33

ゲーム内容ですが 岩をクリックして岩に当たると自動で攻撃モーションが走り岩が消えると待機モーションに戻りたいのですが
提示コードのコメント部内部のコードですが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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

sakura_hana

2021/07/14 02:11

コード上だとAttackExitを呼んでいる箇所が無いので当然実行されません。 どのタイミングで呼びたいのか質問文だとよくわからないので整理して自分でも試してください。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問