예제 #1
0
    public override void DoUpdate()
    {
        base.DoUpdate();

        if (target == null)
        {
            target = GameManager.Instance.GetRandomChicken();

            if (target != null)
            {
                ((AnimalChase)fsm.GetState(AnimalStateType.Chase)).SetChaseTransform(target.transform);

                if (fsm.CurrentState != AnimalStateType.Chase)
                {
                    fsm.GotoState(AnimalStateType.Chase);
                }
            }
            else if (fsm.CurrentState != AnimalStateType.Idle)
            {
                fsm.GotoState(AnimalStateType.Idle);
            }
        }

        if (fsm.CurrentState == AnimalStateType.Chase)
        {
            float distanceToTarget = Vector3.Distance(this.transform.position, target.transform.position);

            if (distanceToTarget < chaseUntilDist)
            {
                target.Die();
                target = null;
                fsm.GotoState(AnimalStateType.Idle);
            }
        }
    }