Getting the object color

I have 2 squares, square one has a random color which gets set on play. square two I want to set the same as square one. I am setting the first square with random using this code:

How do I set square two with square ones color?

var color = GetComponent<Image> ().color;
		color = new Color (Random.Range (0f, 1f), Random.Range (0f, 1f), Random.Range (0f, 1f));
		GetComponent<Image> ().color = color;

add a public variable for the other image in your code. then access it’s color property.

something like this:

// put this on top of your class (or anywhere as long as its outside any function)
public Image otherSquare; // drag this in inspector

...
    
var color = new Color (Random.Range (0f, 1f), Random.Range (0f, 1f), Random.Range (0f, 1f));
GetComponent<Image> ().color = color; // set my color
otherSquare.color = color; // set other color