Camera Not Enabling During Jumpscare Sequence

Hi everyone,

I’m currently working on a horror game in Unity, and I’m running into an issue where my jumpscare camera doesn’t enable during a specific sequence. Here’s the setup:

  1. I have two cameras:
  • A main camera that handles normal gameplay.
  • A jumpscare camera that should be enabled during a jumpscare sequence.
  1. The jumpscare camera is initially disabled and has its own animator with a single animation (triggered via an “Any State” transition with a trigger called “jump”).
  2. In the animation controller for the jumpscare camera, I set it up so that when the “jump” trigger is activated, it transitions to the jumpscare animation.
  3. When the AI catches the player, the following code is called:
Debug.Log("caught"); // This shows up in the console
aiAnim.ResetTrigger("walk");
aiAnim.ResetTrigger("idle");
hideText.SetActive(false);
stopHideText.SetActive(false);
aiAnim.ResetTrigger("sprint");
aiAnim.SetTrigger("jumpscare");
StartCoroutine(deathRoutine());
Debug.Log("caught");
jumpscareCamera.enabled = true; // This doesn't seem to work
Player.SetActive(false);
jumpscareAnimator.SetTrigger("jump");
chasing = false;

  1. The deathRoutine() coroutine works fine, and everything else in the jumpscare sequence seems to be triggering properly. The problem is:
  • The jumpscare camera doesn’t enable.
  • Instead, the screen shows “Display 1: No Cameras Rendering.”
  • The console also logs: “Animator is not playing AnimatorController”, which I believe refers to the jumpscare camera’s animator.
  1. The near clipping plane of the cameras has been modified (decreased to avoid seeing through walls), but I reset it to its original value after realizing it was causing issues with other functionality. This doesn’t seem related to the current problem but might be worth mentioning.

What I’ve Tried:

  • Ensuring that the jumpscare camera’s Animator component is enabled. It is currently enabled.
  • Double-checking that the camera’s layer is properly set to “Everything” and that no layers are excluded.
  • Manually enabling the jumpscare camera in the Inspector during runtime — it works, so the camera itself isn’t broken.
  • Confirming that the “jump” trigger is being set in the jumpscare camera’s animator — it is, but the animation doesn’t seem to play.
  • Adjusting the priority of the cameras (though enabled = true should already make the jumpscare camera active).

What I Need Help With:

  • Why doesn’t the jumpscare camera enable properly, even though jumpscareCamera.enabled = true is called in the code?
  • Could the “Animator is not playing AnimatorController” error be the cause? If so, how can I fix it?
  • Is there something I’m overlooking with camera switching logic or Animator setup?

Any help would be greatly appreciated! Let me know if I need to provide more details or screenshots.
here is the entire current code if you need:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.SceneManagement;

public class haterAI : MonoBehaviour
{
    public NavMeshAgent ai;
    public List<Transform> destinations;
    public Animator aiAnim;
    public float walkSpeed, chaseSpeed, minIdleTime, maxIdleTime, idleTime, sightDistance, catchDistance, chaseTime, minChaseTime, maxChaseTime, jumpscareTime;
    public bool walking, chasing;
    public Transform player;
    Transform currentDest;
    Transform previousDest;
    Vector3 dest;
    public Vector3 rayCastOffset;
    public string deathScene;
    public float aiDistance;
    public GameObject hideText, stopHideText;
    private bool hasPlayedSpottedSound = false;
    public Camera jumpscareCamera;
    public Animator jumpscareAnimator;
    public GameObject Player;
    void Start()
    {
        walking = true;
        previousDest = null;
        currentDest = GetRandomDestination(); 
    }

    void Update()
    {
        Vector3 direction = (player.position - transform.position).normalized;
        RaycastHit hit;
        aiDistance = Vector3.Distance(player.position, this.transform.position);

        if (Physics.Raycast(transform.position + rayCastOffset, direction, out hit, sightDistance))
        {
            if (hit.collider.gameObject.tag == "Player")
            {
                if (!hasPlayedSpottedSound) // Check if the sound has already been played
                {
                    FindObjectOfType<AudioManager>().Play("spotted");
                    hasPlayedSpottedSound = true; // Set the flag so the sound doesn't replay
                }

                walking = false;
                StopCoroutine("stayIdle");
                StartCoroutine("chaseRoutine"); // Start the chase routine only if it's not already running
                chasing = true;
            }
        }

        if (chasing == true)
        {

            
            dest = player.position;
            ai.destination = dest;
            ai.speed = chaseSpeed;
            aiAnim.ResetTrigger("walk");
            aiAnim.ResetTrigger("idle");
            aiAnim.SetTrigger("sprint");


            if (aiDistance <= catchDistance)
            {
                jumpscareCamera.enabled = true;
                aiAnim.ResetTrigger("walk");
                aiAnim.ResetTrigger("idle");
                hideText.SetActive(false);
                stopHideText.SetActive(false);
                aiAnim.ResetTrigger("sprint");
                aiAnim.SetTrigger("jumpscare");
                StartCoroutine(deathRoutine());
                Debug.Log("cought");
                FindObjectOfType<AudioManager>().Play("jumpscare");
                Player.SetActive(false);
                
                jumpscareAnimator.SetTrigger("jump");
                //TriggerJumpscare();
                //StartCoroutine(Ending());
                chasing = false;


            }
        }

        if (walking == true)
        {
            dest = currentDest.position;
            ai.destination = dest;
            ai.speed = walkSpeed;
            aiAnim.ResetTrigger("sprint");
            aiAnim.ResetTrigger("idle");
            aiAnim.SetTrigger("walk");

            if (ai.remainingDistance <= ai.stoppingDistance)
            {
                aiAnim.ResetTrigger("sprint");
                aiAnim.ResetTrigger("walk");
                aiAnim.SetTrigger("idle");
                ai.speed = 0;
                StopCoroutine("stayIdle");
                StartCoroutine("stayIdle");
                walking = false;
            }
        }
    }

    public void stopChase()
    {
        walking = true;
        chasing = false;
        hasPlayedSpottedSound = false; 
        StopCoroutine("chaseRoutine");
        currentDest = GetRandomDestination(); 
    }

    IEnumerator stayIdle()
    {
        idleTime = Random.Range(minIdleTime, maxIdleTime);
        yield return new WaitForSeconds(idleTime);
        walking = true;
        currentDest = GetRandomDestination(); 
    }

    IEnumerator chaseRoutine()
    {
        
        chaseTime = Random.Range(minChaseTime, maxChaseTime);
        yield return new WaitForSeconds(chaseTime);
        stopChase();
    }

    IEnumerator deathRoutine()
    {
        yield return new WaitForSeconds(2f);
        SceneManager.LoadScene(deathScene);
    }

   
    Transform GetRandomDestination()
    {
        Transform newDest;

       
        do
        {
            newDest = destinations[Random.Range(0, destinations.Count)];
        } while (newDest == previousDest && destinations.Count > 1);

        previousDest = newDest; 
        return newDest;
    }
    void TriggerJumpscare()
    {
        Debug.Log("trigger");
        jumpscareCamera.enabled = true;
        Player.SetActive(false);
        jumpscareAnimator.SetTrigger("jump");



    }
    IEnumerator Ending()
    {
        yield return new WaitForSeconds(1f);
        SceneManager.LoadScene("scene");
    }
}