- Home /
Question by
RVDL_IT · May 06, 2017 at 11:28 PM ·
c#colliderreferenceoncollisionenter
How to reference another object's collider for OnCollisionEnter.
Just as the title says. I assume you have to use GetComponent.
Comment
Best Answer
Answer by Ruri-Dev · May 06, 2017 at 11:40 PM
That collision event has the following form: Collider.OnCollisionEnter(Collision other). This means the collider receiving the event also receives an object of type Collision attached to the event as a parameter, on of the properties in that class is the collider property which contains the collider that was hit. Basically you just need other.collider
to access it.
You can also get and use any components from the hit object using:
T component = other.gameObject.GetComponent<T> ();
if (component != null) {
component.Foo ();
}
Your answer
Follow this Question
Related Questions
How to detect collisions in C# 2 Answers
Multiple Cars not working 1 Answer
Destroying Cubes With OnCollisionEnter 1 Answer
How to Give OnCollisionEnter Priority for 2 prefabs ? 1 Answer