Ejemplo n.º 1
0
    protected override IEnumerator Idle()
    {
        int i = Random.Range(0, movePoints.Length);

        target = movePoints[i];

        float time = 0f;

        Debug.Log("Idle Enemy");

        while (isNewState == false)
        {
            yield return(null);

            time += Time.deltaTime;
            if (MoveUtil.DetectPlayer(player.transform, transform, sightRange))
            {
                SetState(State.AttackRun);
            }
            else
            {
                if (time >= 1f)
                {
                    SetState(State.Patrol);
                }
            }
        }
    }
Ejemplo n.º 2
0
    IEnumerator Patrol()
    {
        //Debug.Log("Patrol " + isNewState);
        //Debug.Log("Moving Enemy");

        while (isNewState == false)
        {
            yield return(null);

            //float dist = Vector3.Distance(target.transform.position, transform.position);
            //Debug.Log("InPatrol" + Mathf.Round(dist));

            if (MoveUtil.Move(target.transform.position, cc, patrolPoint, moveSpeed, rotationSpeed))
            {
                //Debug.Log(Vector3.Distance(target.transform.position, transform.position));

                if (MoveUtil.DetectPlayer(player.transform, transform, sightRange))
                {
                    SetState(State.AttackRun);
                }

                if (Vector3.Distance(target.transform.position, transform.position) < 1f)
                {
                    SetState(State.Idle);
                }
                //if (MoveUtil.DetectPlayer(target.transform, gameObject.transform, sightRange))
                //{

                //    SetState(State.AttackRun);
                //}
            }
        }
    }
Ejemplo n.º 3
0
    protected override IEnumerator AttackRun()
    {
        while (isNewState == false)
        {
            yield return(null);

            if (MoveUtil.Move(player.transform.position, cc, sightRange, moveSpeed, rotationSpeed))
            {
                if (MoveUtil.DetectPlayer(player.transform, transform, attackRange))
                {
                    SetState(State.Attack);
                }
            }
            if (Vector3.Distance(player.transform.position, transform.position) > sightRange)
            {
                target = null;
                SetState(State.Idle);
            }
        }
    }