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.

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.

==

Add an F. or an f, if you prefer.

titleWidth = Screen.width*( titleTexture.width / 996F);

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