'Collision' does not contain a definition for 'GameObject

Hi everyone,

I get this error message and can’t figure it out… Any help ?

‘Collision’ does not contain a definition for ‘GameObject’ and no accessible extension method ‘GameObject’ accepting a first argument of type ‘Collision’ could be found (are you missing a using directive or an assembly reference?)

Thx

Found it !

wrote GameObject instead of gameObject…
Don’t quite get those capital or not rules…

Hi Boris,

Good job on spotting and solving the problem yourself. :slight_smile:

As a general rule (with exceptions): Classnames start with a capital letter. Variables start with a minuscule letter. The compiler does not care as long as the spelling is correct. It’s just a naming convention created by us humans to make the code more readable for us.

If you write a class, let’s say MyClass, and declare a variable of that type, you do this:

MyClass myClass;
MyClass anotherClass;
MyClass myObject;
MyClass abc;

In the UnityEngine, there is a variable/property named gameObject. Since Unity, fortunately, follows the most common C# naming convention, we can immediately see that this is a variable/property. And, according to this logic, GameObject is the class.

One more thing: A class name never stands for itself. You will never find a random GameObject; or MyClass; in anybody’s valid code. If you see a lonely name, it’s usually a variable/property.

Two examples:

GameObject player = gameObject;
GameObject player2 = GameObject.Find("Player");

I hope this helped. :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms