I'm experimenting since morning and these are results I got so far.
When you compare two gameobjects directly with "==" operator, it only returns true if they are exactly same object (they must refer to "same instance" of "same object"). It's even returning false if you are comparing two different instances of same object (for example two clones from same prefab).
When you use GetType(), it always returns true as they are all type of "GameObject".
And comparing transforms are a whole different thing.
So actually, you can not get a "true" for not-same-instanced gameobjects (this means they are completely the same thing, so it would be better to use "gameobject" instead "gameobjets") unless you "tweak" a bit.
For my project, i personally decided to compare names. As my gameobjects coming from same prefab, their name are all same ((Clone)PrefabName), but if yours are not named same, then you can use tags, or maybe you can find another solution for this.
Best wishes.
↧