How do I Find which collider has been triggered during onTriggerEnter() event
I am currently working on a script to place objects in the game world, while checking to make sure they are not under ground or floating in the sky. To do this I have put 4 colliders on each leg of the platform and one on its top. Right now the script can tell me when one of the hit boxes is triggered, but not which ones. I have each hit box saved as a variable but I do not know how to figure out which one has triggered the event. Is there a variable that can tell me this info or is there some other way to differentiate?
using UnityEngine;
using System.Collections;
public class PlacementBehaviour : MonoBehaviour {
//these variables contain the individual colliders
public BoxCollider leg1;
public BoxCollider leg2;
public BoxCollider leg3;
public BoxCollider leg4;
public BoxCollider top;
//not yet used
private Vector3 pos;
void OnTriggerEnter(Collider other) {
Debug.Log ("aaaa"); // always prints when a collision occers
Debug.Log (other);
//always prints, but does not specify which collider has been triggered
if(other.gameObject.name == "Terrain")
{
Debug.Log ("hit!");
}
}
}
Comment
@Steven$$anonymous$$cTowelie When I deleted my Answer, it deleted the associated comments.
I re-read your goal and did some searching and looks like the simplest way is to do child gameObjects.