Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (!m_Character.IsDead)
        {
            if (Vector3.Distance(transform.position, player.transform.position) <= visionDistance)
            {
                RaycastHit hit;

                Vector3 targetDirection = (player.transform.position - transform.position).normalized;
                Ray     ray             = new Ray(transform.position, targetDirection);
                if (Physics.Raycast(ray, out hit, visionDistance, layerMask))
                {
                    if (hit.collider.CompareTag("Body"))
                    {
                        m_NavMeshAgent.ResetPath();
                        m_NavMeshAgent.updateRotation = false;
                        RotateTowards(player.transform.position);
                        if (shoot)
                        {
                            weapon.Fire();
                        }
                    }
                }
            }
            else
            {
                WalkTowards(player);
            }
        }
        else
        {
            m_NavMeshAgent.enabled = false;
            Destroy(gameObject, 5f);
        }
    }
Exemplo n.º 2
0
    private IEnumerator FireEventHelper(FireEvent fireEvent)
    {
        if (fireEvent.delay > 0.0f)
        {
            yield return(new WaitForSeconds(fireEvent.delay));
        }

        for (int i = 0; i < fireEvent.shotCount; i++)
        {
            weapon.Fire();
            yield return(new WaitForSeconds(fireEvent.fireRate));
        }

        //shot count of -1 means shoot forever
        if (fireEvent.shotCount == -1)
        {
            while (true)
            {
                weapon.Fire();
                yield return(new WaitForSeconds(fireEvent.fireRate));
            }
        }
    }