Hello,
I am trying to build a mechanic for my game where there is a light source around the player that slowly shrinks overtime. I have built min and max light to set the size within a certain range. Everything is working properly so far, except for when I want to change the variables float value. The scale is targeted properly and shrinks, but Unity remembers the initial value I typed into the variable for some reason. Even if I change the variable value in the script, save the script and reset it nothing happens. The only way it changes is when I rename the variable. I have checked in every other script to see if I am referencing it, but I am not. The only place the scale of that object is being changed is in the light script. So once new the minimum size is hit, the object’s scale will continue to decrease to what the variable was initially given for a value.
Funny thing is, when I look at the inspector everything should theoretically be working 100% smoothly. In the inspector the lightAmount float value is always working properly and stops where it should all the time, but the scale is not always relative to that number.
I am using the most recent version of Unity 5, here is my code:
public class LightSize : MonoBehaviour
{
private GameObject Light;
public float lightAmount;
public float minLight = 0.45f;
public float maxLight = 1.5f;
void Awake()
{
Light = GameObject.FindGameObjectWithTag(“Light”);
lightAmount = maxLight;
}
void FixedUpdate()
{
if (lightAmount >= maxLight)
{
lightAmount = maxLight;
}
if (lightAmount >= minLight)
{
lightAmount -= 0.001f;
}
else
{
Debug.Log(“YOU ARE AT MINIMUM LIGHT”);
}
Light.transform.localScale = new Vector2(lightAmount, lightAmount);
}
}