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

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

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

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

Unity

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

Q&A

解決済

1回答

5007閲覧

[Unity] ゲームオブジェクトがDestroyされかどうかを取得したい。

退会済みユーザー

退会済みユーザー

総合スコア0

C#

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

Unity

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

0グッド

0クリップ

投稿2021/07/12 00:12

提示コード下部のコメント部内部のコードですがプレイヤーがブロックを攻撃してブロックがDestroyされたら攻撃モーションのフラグをfalseにしたいのですがどうすればDestroyしたかどうかを取得出来るのでしょうか? オブジェクトが消えるのでそれを利用して当たり判定を抜けたら
フラグを下げるというやり方を試しましがだめでした

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 91 92 93 //Debug.Log(rb.velocity.magnitude); 94 95 96 Motion(); //モーション 97 Attack(); //攻撃 98 Move(); //移動 99 } 100 101 102 103 104 private void OnTriggerEnter(Collider 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 OnTriggerStay(Collider other) 124 { 125 if (other.gameObject.tag == "AttackArea") 126 { 127 isAttack = true; 128 } 129 } 130//////////////////////////////////////////////////////////////////////////// 131 private void OnTriggerExit(Collider other) 132 { 133 134 if (other.gameObject.tag == "AttackArea") 135 { 136 isAttack = false; 137 } 138 139 } 140//////////////////////////////////////////////////////////////////////////// 141 142 //イベント処理 143 public void AttackStart() 144 { 145 Debug.Log("Attack Start "); 146 weaponScript.collider.enabled = true; 147 } 148 149 public void AttackEnd() 150 { 151 Debug.Log("Attack End "); 152 153 weaponScript.collider.enabled = false; 154 } 155} 156

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

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

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

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

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

guest

回答1

0

ベストアンサー

以下のやり方でnullの場合はdelete されているということで実装出来ました・

cs

1if(gameobject == null) 2{ 3 4}

投稿2021/07/12 01:24

退会済みユーザー

退会済みユーザー

総合スコア0

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

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

YT0014

2021/07/12 03:30

変数 gameobject に関する情報がないので、他者の参考にならない
kyooo_

2021/07/12 05:17

プラス汎用性?拡張性?が無さそうな気がする
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.46%

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

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

質問する

関連した質問