Variable outcome is wrong?!?

Hello!
I am working on my minimap and I use Camera.rect to set minimap in right position but I am having a very weird problem. Heres code :

var minimap : GameObject;
var camheight = Screen.height/10;

function Update () {
	minimap.camera.rect = Rect((Screen.width-camheight)/Screen.width,0,.2,.2);
	Debug.Log(camheight);
	Debug.Log(Screen.width);
	Debug.Log((Screen.width-camheight)/Screen.width);
}

My problem is that It returns (0,0,.2,.2) altho it should be different. I used debug log to get all variables and using calculator got 0.9412… but unity returns 0! Please help I’m so confused.

If you divide two integers the result will also be an integer e.g. 5 / 2 will be 2 instead of 2.5. In your case it’s (Screen.width-camheight)/Screen.width what returns an int. To get a float just write 10.0 instead of 10.

Here are to simple examples:

Debug.Log("int: " + (5 / 2)); //returns 2

Debug.Log("float: " + (5 / 2.0)); //returns 2.5

You’re running up against dividing integers. When you divide two integers, you get an integer result. So 3/2 = 1 if they’re integers. On the other hand, 3.0/2 = 1.5 (because 3.0 is a floating point number). You can also do (float)3/2 to force it to be a float.

All that said, when you divide the screen.height by 10, trying doing it by 10.0 You could also add (float):
minimap.camera.rect = Rect( (float)(Screen.width-camheight)/Screen.width,0,.2,.2);

Javascript doesn’t require you to explicitly declare the type of your variables, so the compiler guesses at the type. In this case, I think your variable camheight is getting typed as an integer because of the 10. Then when you use that, it treats it as an integer.

Here’s an article about this functionality