Convert string to Int - C#

I have global.kills which is a string “10”, but I want to convert it to an int called theKills. (When I check the type with Debug.Log, global.kills returns as a “Single”)

I’ve tried this: int theKills = int.Parse(global.kills);

Which results in the following error: The best overloaded method match for `int.Parse(string)’ has some invalid arguments

My google links are all purple but I cannot find a way to convert this. Any help really appreciated

are you 100% sure global.kills is a string?

1 Like

Not 100% sure- when I try: Debug.Log (global.kills.GetType());

The result is: System.Single

On Googling though I couldn’t find information on “Single”. When I just Debug global.kills the result is a number (The number of kills the player has gotten).

http://msdn.microsoft.com/en-us/library/ya5y69ds

float == System.Single
±1.5e−45 to ±3.4e38

2 Likes

So its a float.
if you really want it as int, use (int)global.kills

1 Like

You might want to figure out why you got it as a float too, since you can’t have a fraction of a kill, so why not int

2 Likes