- Home /
Dealing with Texture2D.width as it is a float number
Hi,
I need to do a simple task, Get the width of the texture in pixels and divide it with another number in order to get a scaling factor.
eg:
titleWidth = Screen.width*( titleTexture.width / 996);
I should get a number like 0.289 but I keep getting plain 0.
I guess it's some float/integer problem.
Thanx in advance.
Answer by equalsequals · Jul 05, 2011 at 04:24 PM
You're dividing a float by an int and an int can't give you decimals so it rounds to 0. Divide it by 996F or 996.0F.
Hope that helps.
==
Answer by Jessy · Jul 05, 2011 at 04:25 PM
Add an F. or an f, if you prefer.
titleWidth = Screen.width*( titleTexture.width / 996F);
Answer by nikola82 · Feb 22, 2015 at 09:40 PM
OK
string W_ = GUI_Texture.width.ToString(); string H_ = GUI_Texture.height.ToString(); // WORKS 100%
float W_FLOAT = float.Parse(W_); float H_FLOAT = float.Parse(H_);
float COEFICIENT__ = W_FLOAT/H_FLOAT;
//We got operation on texture dimensions
Your answer
Follow this Question
Related Questions
Checking an increasing number 1 Answer
Rounded particle motion 0 Answers
GUI.HorizontalSlider precision 3 Answers
int myX = (int)transform.position.x; 1 Answer
C# divide float by integer 2 Answers