実現したいこと
2つの同じオブジェクト同士が衝突したときに、それらのオブジェクトが消えて、新たに1つの違うオブジェクトを生成したい。
現状
衝突時に、2つのオブジェクトで下記のコードが実行されてしまい、新たに作りたいオブジェクトが2つ生成されてしまう為、1つだけ生成する為の方法を教えていただきたいです。
該当のソースコード
Unity
1using System.Collections; 2using System.Collections.Generic; 3using Unity.VisualScripting; 4using UnityEngine; 5 6public class NewBehaviourScript : MonoBehaviour 7{ 8 public GameObject xxxx; 9 private void OnCollisionEnter2D(Collision2D collision) 10 { 11 12 if (collision.gameObject.name.Equals("yyyy")) 13 { 14 Vector2 center = (this.gameObject.transform.position + 15 collision.gameObject.transform.position) * 0.5f; 16 Destroy(this.gameObject); 17 Destroy(collision.gameObject); 18 Instantiate(xxxx, center, Quaternion.identity); 19 } 20 } 21}

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。