Exemple #1
0
    //called when our ghost changes states
    public void ghostStateChange(mGhostState newState)
    {
        state = newState;
        switch (state)
        {
        case mGhostState.Waiting:
            navAgent.isStopped      = true;  //Stop the ghost from moving
            capsuleCollider.enabled = false; //disable the ghosts collision

            //If we are not currently counting down already, reset our timer
            if (!waitCountDown)
            {
                currentTimer = huntTimer;
            }
            waitCountDown = true;
            break;

        case mGhostState.Hunting:
            capsuleCollider.enabled = true;    //Enable collision for our ghost

            //If we have already set an active mirror (which is not the case when first playing the level), set the active mirrors isActive bool to false
            if (SceneManager.Instance.activeMirror != null)
            {
                SceneManager.Instance.activeMirror.GetComponent <MirrorHuntZone>().isActive = false;
            }
            //Set the mirror we are currently standing in to the active mirror
            SceneManager.Instance.activeMirror = SceneManager.Instance.currentMirror;
            //Flag this mirror as active
            SceneManager.Instance.activeMirror.GetComponent <MirrorHuntZone>().isActive = true;

            // Set the speed of our ghost relative to our players max speed
            navAgent.speed = SceneManager.Instance.player.maxSpeed * 1.5f;

            //Make sure all our ghost timers are turned off
            hitCountDown = waitCountDown = false;
            //Allow our ghost to move
            navAgent.isStopped = false;
            break;

        case mGhostState.Cooldown:
            navAgent.isStopped      = true;  //Stop the ghost from moving
            capsuleCollider.enabled = false; //disable the ghosts collision

            //If we are not currently counting down already, reset our timer
            if (!hitCountDown)
            {
                currentTimer = attackDelayTimer;
            }
            hitCountDown = true;
            break;

        case mGhostState.Idle:
            navAgent.isStopped      = true;  //Stop the ghost from moving
            capsuleCollider.enabled = false; //disable the ghosts collision
            break;
        }
    }
Exemple #2
0
    void ghostAttack()
    {
        //Put the ghost on a brief cooldown after landing an attack
        state = mGhostState.Cooldown;

        navAgent.isStopped      = true;  //Stop the ghost from moving
        capsuleCollider.enabled = false; //disable the ghosts collision

        //If we are not currently counting down already, reset our timer
        if (!hitCountDown)
        {
            currentTimer = attackDelayTimer;
        }
        hitCountDown = true;

        //Cause the player character to take a hit
        SceneManager.Instance.player.enemyHit();
    }
Exemple #3
0
    void Update()
    {
        //Always look at the player
        transform.LookAt(SceneManager.Instance.player.transform);

        //Determines our behaviour based on our ghosts current state
        switch (state)
        {
        case mGhostState.Hunting:
            //Move towards the player character
            navAgent.destination    = SceneManager.Instance.player.transform.position;
            capsuleCollider.enabled = true;
            break;

        case mGhostState.Cooldown:
            if (!hitCountDown)
            {
                return;    // If we are not waiting for the hit timer to count, return
            }
            else
            {
                currentTimer -= Time.deltaTime;
                //When our timer hits 0
                if (currentTimer < 0)
                {
                    hitCountDown = false;
                    //change the state of our ghost to hunt
                    state = mGhostState.Hunting;

                    // Set the speed of our ghost relative to our players max speed
                    navAgent.speed = SceneManager.Instance.player.maxSpeed * 1.5f;

                    //Make sure all our ghost timers are turned off
                    hitCountDown = false;
                    //Allow our ghost to move
                    navAgent.isStopped = false;
                }
            }
            break;

        case mGhostState.Idle:      //starting state, don't do anything
            break;
        }
    }