Ejemplo n.º 1
0
    void ChooseNewState()
    {
        bool DistanceCheck = Vector3.Distance(transform.position, GetTarget()) < RangeToTarget;

        if (DistanceCheck && bAllowToTalk)
        {
            //Search for a QuestManager
            QuestionaryEvent QuestMngr = GameObject.FindObjectOfType <QuestionaryEvent>();
            if (QuestMngr)
            {
                //Mini Game starts
                mState = State.Talking;
                QuestMngr.InitNewQuestionary(ActivePlayer, this.gameObject);
            }
        }
        else
        {
            //Select a new State
            if (Random.value > 0.25f)
            {
                //Move
                if (GrMvment)
                {
                    GrMvment.Stop();
                }

                mState = State.Walking;
                //Get a new Position
                float CameraVertBound = Camera.main.orthographicSize;
                float CameraHorzBound = CameraVertBound * Screen.width / Screen.height;

                TargetPosition = new Vector3(Random.Range(-CameraHorzBound, CameraHorzBound), Random.Range(-5, 15), 0);
                RangeToTarget  = Random.Range(1, 3);
                bRotate        = true;
            }
            else
            {
                //Idle
                mState = State.Idle;
                if (GrMvment)
                {
                    GrMvment.ReStart();
                }
            }
        }


        TimeOnSameState = 0.0f;
        if (ChangeState != null)
        {
            ChangeState(mState);
        }
    }