Collecting blocks + score system

Hi all,

I’m making a little game in which the players task is to collect little colored blocks and push them in a box (see screenshot).
The red ones are worth 5 points,
the yellow ones are worth 2 points,
and the blue ones are worth 1 point.

Only problem is, I don’t know how to create this score system :stuck_out_tongue: I’m more of a game artist, so I really need help with the scripting and I hope I’ll get that help from you guys!

I know how the script has to look like.
I probably need to make a (invisible) cube in front of the box with a script added, which says:

If a blue box collides with me:
score + 1

If a yellow box collides with me:
score + 2

If a red box collides with me:
score + 5

But I really don’t know how to write this script in C Sharp/Java. Can anyone help me with this?

Anyone?
The deadline is in 3 hours and this is the only thing that doesn’t work yet :stuck_out_tongue:

Well, I guess this is too late for the deadline, but anyway…

One way to handle this is to give the objects tags, so all the blue boxes might be tagged with “Blue”, etc. You would have a trigger collider on the box and an OnTriggerEnter function in the box’s script. This function gets passed as a parameter the collider that entered the trigger. You can get the object’s tag from the collider, so the code would look something like:-

function OnTriggerEnter(other: Collider) {
    if (other.tag == "Blue") {
        score += 1;
    } else if (other.tag == "Yellow") {
        score += 2;
    } else if (other.tag == "Red") {
        score += 5;
    }
}