Count Objects with specific colour

Hello Unity Answers.
In my scene I have 20 cubes for witch I specify a colour through java script on mouse click. Each of them have a tag “Tile”. How do I filter GameObjects list to count objects with lets say “blue” colour and perform an action when it’s less than specified amount?

var counter : int;
var specifiedAmount : int;

function Update()
{
    counter = 0;

    for(var go : GameObject in GameObject.FindGameObjectsWithTag("Tile"))
    {
        if(go.renderer.material.color == Color.blue)
        {
            counter++;
        }
    }

    if(counter < specifiedAmount)
    {
        // Amount of blue objects is less then specified amount.
    }
}

This will do it for you. Just make sure those objects are really blue. If you’re not sure what color they actually are, find out then assign it to a variable that is type of Color and change this line.

if(go.renderer.material.color == Color.blue)

to this

if(go.renderer.material.color == MyCustomColor)

Good luck.