Exemplo n.º 1
0
    public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        personAI.target = playerTransform.position;
        Vector3 lookAtPlayer = playerTransform.position - personAI.transform.position;

        RaycastHit hit;

        if (!Physics.Raycast(animator.transform.position + Vector3.up, lookAtPlayer, out hit, PersonAI.visionDepth, ~LayerMask.GetMask("Ignore Raycast")) ||
            (hit.collider.tag != "Player"))
        {
            //Line of sight is broken, switch to walk state with last seen position as target
            personAI.stateMachine.SetTrigger("Idle");
            personAI.stateMachine.SetTrigger("Noise");
            personAI.HearSomething(playerTransform.position);
            return;
        }

        personAI.transform.rotation = Quaternion.LookRotation(lookAtPlayer, Vector3.up);

        shootDelay -= Time.deltaTime;
        if (shootDelay <= 0f)
        {
            Debug.Log(animator.transform.name + " Bang!");
            personAI.Shoot();
            shootDelay = shootInterval;
        }
    }
Exemplo n.º 2
0
    public void Scream()
    {
        Collider[] colliders = Physics.OverlapSphere(transform.position, 8f, LayerMask.GetMask("Person"));
        foreach (Collider c in colliders)
        {
            if (c.transform == transform)             // Don't scare yourself
            {
                continue;
            }

            PersonAI person = c.transform.GetComponent <PersonAI>();
            if (person)
            {
                person.HearSomething(transform.position);
            }
        }
    }