transfering string to int?

in my score script I have this variable public int heightScore; I wanted to make the variable heightScore my players Y position. heightScore = int.Parse(player.position.y.ToString("0")); and it worked but now I want to make another variable in another c# file the same as my heightScore. so I thought I make this: public Score theHeightScore; and my other variable like this: public int coinsGet; and just make them the same like this: (this is also the line that gives the error) coinsGet = theHeightScore.heightScore.ToString("0"); but if I go back to unity it gives me this error: Assets\Scripts\CoinsCollect.cs(16,20): error CS0029: Cannot implicitly convert type 'string' to 'int'

can someone explain to me how I can fix this?
thank you!

I did this a couple of weeks ago - I went through the same way you did, but it didn’t work well.
I’ll dig out the script and post up the conversion bit. :slight_smile:
You should post up the whole section of your code, to see what exactly is happening on line 20.

in the code generating the error, it looks like you forgot to parse the int. You’re trying to assign coinsGet a string value - toString() and you need to use int.Parse on the right hand side.

But why use toString at all? because heightScore is already an int… unless I am missing something.

Why not just do:

coinsGet = theHeightScore.heightScore;
1 Like