예제 #1
0
    /// <summary>
    /// 追逐
    /// </summary>
    private void OnChase()
    {
        AnimatorStateInfo info = Anim.GetCurrentAnimatorStateInfo(0);

        if (!info.IsName("Move"))
        {
            Anim.SetInteger("State", 0);
        }

        if (Distance <= AttackDis)
        {
            State = E_Sate.Attack;
            return;
        }
        else
        {
            State = E_Sate.Patrol;
        }

        Vector3 patrolDir = Target.position - transform.position;

        if (patrolDir.magnitude > 0.1f && Vector3.Angle(patrolDir, oldPatrolDir) < 150)
        {
            transform.position += patrolDir.normalized * Time.deltaTime * ChaseSpeed;
            Quaternion toRotation = Quaternion.LookRotation(patrolDir);
            transform.rotation = Quaternion.Lerp(transform.rotation, toRotation, Time.deltaTime * 20);
        }
    }
예제 #2
0
    /// <summary>
    /// 攻击
    /// </summary>
    private void OnAttack()
    {
        transform.LookAt(Target.position);

        AnimatorStateInfo info = Anim.GetCurrentAnimatorStateInfo(0);

        if (!info.IsName("Attack"))
        {
            Anim.speed = 4;
            Anim.SetInteger("State", 1);
        }
        else
        {
            if (info.normalizedTime >= 1.0f)
            {
                if (GetTarget)
                {
                    State = E_Sate.Get;
                }
                else
                {
                    State = E_Sate.Miss;
                }
            }
        }
    }
예제 #3
0
    private void OnPatrol()
    {
        AnimatorStateInfo info = Anim.GetCurrentAnimatorStateInfo(0);

        if (!info.IsName("Move"))
        {
            Anim.SetInteger("State", 0);
        }

        if (Distance <= SearchDis)
        {
            State = E_Sate.Chase;
            return;
        }

        Vector3 patrolDir = StartPos - transform.position;

        if (patrolDir.magnitude > 0.1f && Vector3.Angle(patrolDir, oldPatrolDir) < 150)
        {
            transform.position += patrolDir.normalized * Time.deltaTime * PatrolSpeed;
            transform.LookAt(Target.position);
        }
        else
        {
            transform.position = StartPos;
        }
    }
예제 #4
0
    /// <summary>
    /// 攻击命中
    /// </summary>
    private void OnGet()
    {
        AnimatorStateInfo info = Anim.GetCurrentAnimatorStateInfo(0);

        if (!info.IsName("Get"))
        {
            Anim.speed = 4;
            Anim.SetInteger("State", 2);
        }
        else
        {
            if (info.normalizedTime >= 1.0f)
            {
                State = E_Sate.Patrol;
            }
        }
    }