So here’s my script i gonna add some feelings and other stuff that the player expresses. So here i want my “warm” int to be higher every secound IF im not in one of the shadows colliders. Then if i am inside of one, the “warm” int is going to be get lower. It’s also displayed on the screen.
But here’s the problem, the “warm” int never change. And i even set it to 50 in the begining. Help please!
~carlqwe
Code: #pragma strict
var warm : int = 50;
function Update ()
{
}
function OnTriggerStay (Col : Collider)
{
if(!Col.tag == "shadows")
{
warm += 1 * Time.deltaTime;
}
else
{
warm -= 2 * Time.deltaTime;
}
}
function OnGUI ()
{
GUI.Label(new Rect(780, 680, 250, 100), warm.ToString(""));
}
Warm is an integer. You’re adding 1 * Time.deltaTime to it - which is a float. That float will be rounded to an integer before it’s added to the warm variable. In all of the languages used in Unity, rounding is always towards zero.
So, your 1 * Time.deltaTime is somewhere in the realm of 0.01 or lower, so you’re actually never adding (or subtracting) anything from the warm variable. The easiest solution is to just change the warm variable to a float. When you’re printing it, you should probably cast it back to an integer, so it doesn’t print all of the decimal places.