c# 2d How to compare two GameObjects ?
Hello,
I am trying to compare a GameObject that is inside an array of GameObjects (which is the map) to just another GameObject, in this case I am trying to see if where the player stands in the map is water, but even when I know for sure it is water they don't compare. can you plz help me ? , this is my code:
(a script)
public static GameObject[] map;
map = new GameObject[10];
(b script)
map[0] = Water;
(c script)
if (map[0] == Water) {
print ("Works");
} else {
print ("Doesn't Work");
}
I think you should consider positions (like character is in bounds of water of not) for the same ins$$anonymous$$d of Looking for compare.
Answer by Abhiroop-Tandon · Mar 29, 2016 at 08:39 AM
Well if you just want to compare two game objects you can either compare them by their names or tags or on which layer the two objects are. In your case i would agree with @Rushikesh988. You should consider the bounds!!
Your answer
Follow this Question
Related Questions
Doodle Jump Game Platform Spawn Issue Unity2D 0 Answers
How to make the camera stay the same size when changing resolution 1 Answer
Cannot delay player respawn. 2 Answers
How do I get a reference to a script that is on another gameobject 0 Answers
Is there a way I can make one script for all my buttons in my game? 1 Answer