I made a simple "radiation" field through a trigger but it works only when player in move. Function countes two decimal values. What could be the problem?
decimal radIntensity = 0.001m;
decimal currentDose;
private void OnTriggerStay2D(Collider2D area)
{
if (area.gameObject.tag == "Player")
{
currentDose += radIntensity;
}
print($"Current dose: {currentDose} R");
}
In the RigidBody2D component there's an option to disable or enable the sleeping mode.
Try to disable it with the RigidbodySleepMode2D.NeverSleep option.
Also can use a boolean-flag and OnTriggerEnter2D and OnTriggerExit2D. But never sleeping rigidbody is much better
bool _flag;
private void Update()
{
if (_flag)
{
currentDose += radIntensity;
}
print($"Current dose {currentDose} R");
}
private void OnTriggerEnter2D(Collider2D area)
{
if (area.gameObject.tag == "Player")
{
_flag = true;
}
}
private void OnTriggerExit2D(Collider2D other)
{
if (other.gameObject.tag == "Player")
{
_flag = !true;
}