Hello everybody!
I’m writing a game like Roll-a-Ball in tutorials and i want to show coords on the screen, but when i try to play the game the coords are always “0.00”. My code is in the attachment.
Thanks,
happygiraffe
Hello everybody!
I’m writing a game like Roll-a-Ball in tutorials and i want to show coords on the screen, but when i try to play the game the coords are always “0.00”. My code is in the attachment.
Thanks,
happygiraffe
Your string.Format lines actually give FormatException errors when played, but putting that aside, all the conversion you’re doing is overcomplicating things if this is purely for display. You’re text assignment could be as simple as:
text.text = "x: " + position.x + "; y: " + position.y + "; z: " + position.z + ";";
Or if you need the numbers in a specific format, add ToString to the positions, and do something like this:
text.text = "x: " + position.x.ToString("F0") + "; y: " + position.y.ToString("F0") + "; z: " + position.z.ToString("F0") + ";";
You can more format options here: Standard Numeric Format Strings.
paste code in rather than asking people to download files, you’ll get better response rate, especially when you put the code inside [ code][ /code] tags (sticky at the top of the scripting forum)
you need to learn for loops. you shouldn’t be hard coding a line for each item in the arrays…
don’t use “System.Convert.ToString(…)” to convert floats (or in general really) since the system lib doesn’t have one for floats (not entirely sure which it’ll opt for in that case).
you also don’t need to do anything with arrays here…
void Update () {
position = player.transform.position;
text.text = "x: " + position.x + "; y: " + position.y + "; z: " + position.z + ";";
}
should do it