- Home /
Multiplying a string
Hi,guys after all my recent post (sorry there were so many) i managed to bring it all down to only 1 error.Now i dont know how to multiply a string like exptolevel is 1000 how do i multiply that string to 2000?thanks
if you need to multiply things, then maybe you don't need them as strings until it's time to display them.
if you insist on making it hard for yourself then look at ToInt, ToFloat, TryParse, etc.
Answer by MarioAGOrdiano · Jul 15, 2014 at 05:51 PM
If you are going to use a string of numbers for operations you are better of making it an int or float.
Most variable types in unity (all derived form object) have a method to convert them to strings called .ToString()
Like this:
int exptolevel = 1000;
//Here you use the method obj.ToString() to display
void display()
{
//lets imagine you are using GUILayout.Label
//this changes the int exptolevel to a string for this funcion only
GUILayout.Label(exptoLevel.ToString());
//now we can do math with the variable as normal
exptolevel += 1000;
}
Your answer
Follow this Question
Related Questions
Input string was not in the correct format 2 Answers
Parser error for code... 1 Answer
Unexpected error 1 Answer
Switching between two weapons 1 Answer
String Multiplying 1 Answer