How to compare if two gameObjects are the same?

I´m trying to make a game about visual memory. Random a game object appears and after 5 seconds disappear and another one appear. The goal is the player select that game object if is equal to the last one. How can i compare the fist game object and the one that players click?
Any suggestions???

Thanks

Use Object.RefrenceEquals(obj1, obj2)

Like this

if(GameObject.ReferenceEquals( firstGameObject, secondGameObject))
      Debug.Log("first and second are the same");

Also you can use to check if it null ? by changing secondGameObject to null.

Read more about ReferenceEquals

Hope this can help you. :slight_smile:

Use GameObject.GetInstanceID()

if (firstObj.GetInstanceID() == secondObj.GetInstanceID()) {
			// objects are the same instance
		}

… can’t you use

gameObject == otherGameObject

or am I missing something critical…

You could maybe give a special name or tag to the different objects.

“Blue” for blue objects and “Red” for red etc.

Then in a script keep storing the name/tag of the last object that was on the screen in a string and then just do a check to see if the last object’s tag was the same as the one that the user clicked.

Just an Idea…