How to create a fear system like Friday the 13th: The Game?

In my game I want something like Friday the 13th: The Game, where your face and atmosphere changes based on how scared the character is. Like as you get scared, it changes animation states. I’d like to know how to do this. (I’m not good at coding, so being a bit more direct about instructions would be great.)

You could detect if the player is near something that should scare them.


float fear = 0;

Animator anim;
void Start() {
     LayerMask mask = LayerMask.GetMask("Scary");
     //Don't use the " " for get component, I had to add them so it would show up on here
     anim = GetComponent<"Animator">();
}

void Update() {
     Collider[] colliders = Physics.OverlapSphere(transform.position, 15f, mask);
     if (colliders.Length >= 1) {
          fear += (10 * Time.deltaTime);
     }
     else {
         fear -= (10 * Time.deltaTime);
     }
     fear = Mathf.Clamp(fear, 0, 100);
     if (fear >= 50) {
          anim.SetBool("Scared", true);
     }
     else {
          anim.SetBool("Scared", false);
     }
}

If we are within 15 units of something that should scare the player, then our float: fear, will rise. If we are not, then fear will lower. We use Mathf.Clamp to make sure fear never exceeds 0 or 100. If fear is greater than or equal to 50, then we set a bool on our animator: Scared, to true. We can set up a sub-state machine on the animator which contains the alternate animations for the player when they are scared.

The fear system is essentially a complex state machine which takes booleans as input and commands the GUI, textures, animations and in general the feel of the game based on them. If you’re not a good programmer you’ll probably want to master state machines before attempting to code a non-trivial fear system, as is with any serious component you tailor make for a game.

Here are some super easy examples: Simple state machine example in C#? - Stack Overflow