void Update()
    {
        if (!sightDeactivated)
        {
            if (sight.IsObjectInView(GameObject.FindGameObjectWithTag("Player")))
            {
                reaction.OnIntruderInSight();
            }
            else
            {
                reaction.OnIntruderOutOfSight();
            }

            Alertness alertness = reaction.DetermineAlertness();
            if (alertness == Alertness.Aggressive)
            {
                sight.getLight().LightColor = Color.red;
                activateConnectedGadgets();
            }
            else if (alertness == Alertness.Suspicious)
            {
                sight.getLight().LightColor = Color.yellow;
            }
            else if (alertness == Alertness.Normal)
            {
                sight.getLight().LightColor = Color.blue;
            }

            updateRotation();
        }
        else if (!isPossessed())
        {
            turnOnTimerCount -= Time.deltaTime;
            if (turnOnTimerCount <= 0f)
            {
                sightDeactivated = false;
                sight.enabled    = true;
                sight.getLight().LightEnabled = true;
                turnOnTimerCount = turnOnTimer;
            }
        }
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        if (stunTimer > 0)
        {
            stunTimer -= Time.deltaTime;
        }

        if (!isActive || destroyed)         // Do nothing if currently occupied by ai
        {
            return;
        }

        UpdateVisuals();

        if (sight.IsObjectInView(GameManager.gameManager.Robot.gameObject) ||
            Vector3.Distance(transform.position, GameManager.gameManager.Robot.transform.position) < bumpRange)
        {
            reaction.OnIntruderInSight();
            //Try to turn to face the player
            orientation = (int)Mathf.Sign(GameManager.gameManager.Robot.transform.position.x - transform.position.x);
            Vector3 gunPos = gunPosition.transform.localPosition;
            if (orientation == 1)
            {
                gunPos.x = 2.604553f;
            }
            else
            {
                gunPos.x = -2.604553f;
            }

            gunPosition.transform.localPosition = gunPos;
        }
        else
        {
            reaction.OnIntruderOutOfSight();
        }

        alertness = reaction.DetermineAlertness();
        if (stunTimer > 0)
        {
            alertness = Alertness.Normal;
        }
        if (alertness == Alertness.Aggressive)
        {
            if (stunTimer <= 0)
            {
                reactionMethod.OnAggressive();
            }
            if (previousAlertness != Alertness.Aggressive)
            {
                if (alertSound != null)
                {
                    AudioSource.PlayClipAtPoint(alertSound, transform.position);
                }

                animations.Play(animations.Library.GetClipByName("Shoot"));
            }
            activateConnectedGadgets();
            previousAlertness = Alertness.Aggressive;

            //Return so we don't move
            return;
        }
        else if (alertness == Alertness.Suspicious)
        {
            reactionMethod.OnSuspicious();
            if (previousAlertness != Alertness.Suspicious)
            {
                if (suspiciousSound != null && previousAlertness != Alertness.Aggressive)
                {
                    AudioSource.PlayClipAtPoint(suspiciousSound, transform.position);
                }
                animations.Play(animations.Library.GetClipByName("Attack"));
            }
            previousAlertness = Alertness.Suspicious;
            //Don't move if intruder is still in sight
            if (sight.IsObjectInView(GameManager.gameManager.Robot.gameObject) ||
                Vector3.Distance(transform.position, GameManager.gameManager.Robot.transform.position) < bumpRange)
            {
                return;
            }
        }
        else if (alertness == Alertness.Normal)
        {
            reactionMethod.OnNormal();
            previousAlertness = Alertness.Normal;
        }

        if (stunTimer <= 0)
        {
            movement.UpdateMovement();
            orientation = (int)Mathf.Sign(movement.Velocity.x);
            stunSparks.enableEmission = false;
        }
        Vector3 gunPosi = gunPosition.transform.localPosition;

        if (orientation == 1)
        {
            gunPosi.x = 2.604553f;
        }
        else
        {
            gunPosi.x = -2.604553f;
        }

        gunPosition.transform.localPosition = gunPosi;
    }