Hello everyone.
I was wondering, how can i show no GUIText my floats as int. because int takes less space than Strings.
since Time.deltaTime reads only floats i cant just turn everything int. and since String uses more memory than int,
i would like to ask how could i make it int without using .ToString(“f0”)
Mathf.Floor(ToInt) Mathf.Ceil(ToInt) and Mathf.Round(ToInt) do what you want in different ways. ToInt makes them actually cast to an int, but if you’re just going to cast them to a string right away and never actually use the int just use Mathf.Floor(float) Mathf.Ceil(float) or Mathf.Round(float)
The scripting reference will tell you what they do specifically, but it’s simple (floor rounds down, ceil rounds up, round rounds roundly).
If you mean you are worried about the memory usage of the string cast at all, as soon as you assign it to the .text it’s becoming a string anyway. If you say healthGUI.text = myInt or myFloat; what that does behind the scenes is say “healthGUI.text = myInt.ToString() or myFloat.ToString()” - there’s no savings by avoiding the string cast yourself.
Thanks for the info. i will have a look at those. It sounds like Mathf.FloorToInt is what im looking for.
You said it will still read it as ToString. Does the same thing happen with C#? (int)myFloat?
I don’t know of any technique for visually representing numbers on screen without conversion to a string that does not involve writing your own way over-optimized technique. I really, really wouldn’t worry about it personally - regardless of target platform.