using objectname for scoring purposes?

I have many cubes on a plane - each one carrying a different score.

Each cube’s name = its score.

I have problems scripting a score that will use the objectname as an int for an operation:

in particular this error “cannot implicitly convert type ‘string’ to ‘int’” seems to be problem of a script that goes:

public class SCORE : MonoBehaviour {

public static int score = 0 ;
bool isHit = false;

// Use this for initialization
void Start () {
// Update is called once per frame
void Update () {
void OnCollisionEnter(Collision Col) {

if(isHit == false) {
isHit = true;
	score = score +;

Script debugs OK using: score = score + 2;

Any suggestion?

Thank you!


Changing the name of the GameObject isn’t really the best way to store information. Why can’t you just have an int in your Score script? It would be much cheaper to access ints directly than to constantly be creating new strings, setting gameObject’s name, and parsing them into ints.

Thank you guys for your well appreciated suggestions!

Unfortunately, still no luck with my score…

I tried using TryParse but the script does not want to recognize as an int - I fear that I am scripting it wrong somehow - I have never used it before, although I tried many different ways…

You see, I have around 15000 cubes - the 1 player being a sphere that moves around -
aim of the game = score the max by hitting green high-value cubes.

13000 cubes have instead a “turn red if hit” script - they DO NOT matter “score-wise”
2000 cubes have a “turn green if hit” script - they matter “score-wise”

The 2000 cubes are all named individually with 2000 non-repeating numbers - which is why I am trying to use their name for scoring purposes as opposed to writing 2000 different scripts!

Well, should anyone have any other suggestion, that would be grand - in the meantime, I will continue trying with TryParse as it seems the best option so far!

Thank you,


P.S. — each of the 2000 cubes has (on the surface to be hit) a GUI text named “XXX Text” and carrying text = “XXX” (XXX being a number representing the Cube’s name/number) perhaps this can be of use for my scoring purposes instead of using the name of the cube?