- Home /
Collision.contacts issue
Hello,
Im trying to change the material inside a prefab when a gameObject hits the collider inside this same prefab.
Everytime i try to use code examples like this:
// Prints the name of the collider this transform collided with
function OnCollisionEnter(other : Collision) {
print("This collider collided with: " + other.contacts[0].otherCollider.name);
}
The console logs: Assets/Scripts/Collision.js(4,63): BCE0019: 'contacts' is not a member of 'Collision'.
But im sure that contacts is a member of Collision (http://docs.unity3d.com/Documentation/ScriptReference/Collision-contacts.html)
Can Anyone help me with this please?
Answer by thesfid · Oct 01, 2013 at 04:00 PM
function OnCollisionEnter (collision : Collision) {
var contact = collision.contacts[0];
Debug.Log(contact.thisCollider.name + " hit " + contact.otherCollider.name);
}
This works for me.
To be honest, I'm not exactly sure why your solution doesn't work, since it looks like it's essentially long-hand for the "var contact" bit.
Perhaps someone else could explain the details, but hopefully this will work for you.
Your answer
![](https://koobas.hobune.stream/wayback/20220613114221im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity3d Arkanoid platform collision problem 1 Answer
detection cube face while rotating 0 Answers
Object Collision PLEASE HELP!!! 1 Answer