- Home /
Why is collision.contacts causing a compiler error
I am new to Unity Programming so the compiler error has me stumped. Any help is appreciated.
My Code is meant to make a ball reflect, but it is giving me a compiler error on line 11 at collision.contacts. Could anyone tell me what is wrong, because this is what the scripting reference did. I have also tried this with various types of capitalization.
The Compiler's Error is: " 'Collision' does not contain a definition for 'contacts' accepting a first argument of the type 'Collision' could be found"
Thanks The code is:
using UnityEngine;
using System.Collections;
public class Collision : MonoBehaviour {
public Vector3 move;
void Update () {
transform.Translate(move);
}
void OnCollisionEnter (Collision collision) {
ContactPoint contact = collision.contacts[0];
Vector3.Reflect( move, contact.normal);
print("Collision is working!");
}
Answer by Bovine · Jul 11, 2012 at 08:22 AM
Ha, subtle
Your script is defining a new class called Collision in the global namespace so it is hiding UnityEngine.Collision - change the name of your Collision class to say MyCollision and it will all work fine.
Thanks Bovine
Your answer
Follow this Question
Related Questions
Make something happen when touch cube C# 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Fist Punch Collision 0 Answers