現状
Unityでスイッチオブジェクトのコライダーに当たった時動作させたいのですが、子オブジェクトのコライダーに当たった時にも反応してしまいます。
これが仕様なのかもしれませんが、
スイッチオブジェクト(コライダー(スイッチ動作用)、トリガー(カメラの侵入検知用)あり)
_レールオブジェクト(レールの当たり判定用コライダー、ブロックの設置補正用トリガー)
__目印オブジェクト
__目印オブジェクト
のようなオブジェクト関係なっていて、どうにか親オブジェクトのコライダーに当たった時のみ反応するようにしたいのです。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class DeassemblyUnit : MonoBehaviour { 6 private int hitSphereID; 7 private float accellspeed = 2; 8 9 private void OnCollisionEnter(Collision collision) 10 { 11 if (collision.gameObject.tag == "Player") 12 { 13 int i = 0; 14 foreach(GameObject Search in MainDataBase.SphereObj) 15 { 16 if (collision.gameObject.name.Contains(Search.name)) 17 { 18 hitSphereID = i; 19 } 20 i++; 21 } 22 Destroy(collision.gameObject); 23 Vector3 Export1 = transform.Find("DiassemblyUnit").gameObject.transform.Find("Output1").gameObject.transform.position; 24 Vector3 Export2 = transform.Find("DiassemblyUnit").gameObject.transform.Find("Output2").gameObject.transform.position; 25 Export1 += new Vector3(0,1f,0); 26 Export2 += new Vector3(0, 1f, 0); 27 GameObject Export1Obj = Instantiate(MainDataBase.SphereObj[hitSphereID - 1], Export1, Quaternion.identity) as GameObject; 28 GameObject Export2Obj = Instantiate(MainDataBase.SphereObj[hitSphereID - 1], Export2, Quaternion.identity) as GameObject; 29 Vector3 Export1accsell = transform.position - Export1; 30 Vector3 Export2accsell = transform.position - Export2; 31 Export1Obj.GetComponent<Rigidbody>().velocity -= Export1accsell * accellspeed; 32 Export2Obj.GetComponent<Rigidbody>().velocity -= Export2accsell * accellspeed; 33 Export1Obj.name = MainDataBase.SphereObj[hitSphereID - 1].name + Controller.SphereID; 34 Controller.SphereID++; 35 Export2Obj.name = MainDataBase.SphereObj[hitSphereID - 1].name + Controller.SphereID; 36 Controller.SphereID++; 37 } 38 } 39}
念のためソースコードも載せておきます。
要望
子オブジェクトのコライダーは、判定から外したい。
複数のコライダーのうち指定したコライダーに当たった時のみのみ反応させたい。
出来る限り遅延がないようにしたいです。
環境
Unity2018.2.2f1 Personal(64bit)
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/18 22:11