Damage over time while colliding.

I am really sorry if this doesn’t end up very clear, I tend to avoid using forums because I never know how to frame my questions.

The situation is that I have two objects; a Player, with a stat called Fear that by default is set to 0, and an Enemy that has a collider covering an area surrounding it.

Essentially what I am trying to do is raise the value of the Player’s fear by 1/sec while in close proximity to the Enemy.

I am still very new to coding, and am struggling to understand how scripts communicate with each other.

If this is not enough information, please let me know what else you need.

I dont know if my script work but you put this script on you player and you need to give the enemy the “Enemy” tag. Then It should increase the fear if the player stays in collision with the enemy. Im new to coding too but I still can help somehow, right?

    float Fear = 0f;
    float FearPerSec = 1f;

    void IncreaseFear ()
    {
        Fear += FearPerSec * Time.deltaTime;
    }
  
    private void OnCollisionStay(Collision other)
    {
        If (other.collider.CompareTag("Enemy"))
        {
             IncreaseFear();
        }
    }