- Home /
Collision.gameObject issues
an error keeps popping up whith this. however i can't see it. can anybody else? if (Collision.gameObject == "floor" )
Answer by KellyThomas · Jan 18, 2014 at 04:33 PM
By convention Class names will start with a capital letter, while local variables and function parameters will start with a lower-case letter.
If following this convention:
Collision
(Capital C) is the class and is only able to access static members.
collision
(lower-case C) is an instance and is able to access instance members.
As .gameObject
is an instance member, representing the object involved in this collision, it should be accessed like this: collision.gameObject
The other issue is that you are comparing a gameObject
with a string. It would be better to compare the name or tag like so:
if (collision.gameObject.tag == "floor" )
or
if (collision.gameObject.name == "floor" )
Your answer
Follow this Question
Related Questions
Mouse point offset in Unity Menus 2 Answers
When playing animations in Mecanim they play backwards? 0 Answers
Particle System makes the engine freeze on play mode. 0 Answers
Unity WebGL Failed to load resource: net::ERR_CONTENT_LENGTH_MISMATCH 1 Answer
Pixels inbetwen non conected polygons. 2 Answers