How can i reach other object in script of a object?

I want to compare a sphere color with a cube color. But i don’t know how can i reach the sphere in script of the cube.
May you help me?

Yes i’m new to Unity.

One way to do this is with:


Basically the first part will search all the active GameObjects and find the one with the name you provide. The second part will get that objects Renderer, the material used by that Renderer and then the color of that material.

It’s not recommended that you use Find in the update loop (every frame) because it will slow things down.
So you may want to save the sphere once like this in Start:

GameObject externalSphere = GameObject.Find("NameOfSphere");

And then you can refer to the color like this:


Learn more here