コード例 #1
0
    private void Update()
    {
        //waits until stateSeconds has passed before switching states
        //if (Time.time > gameTimer + 1)
        //{
        //    gameTimer = Time.time;
        //    seconds++;
        //    //Debug.Log(seconds);
        //}

        //if (seconds == stateSeconds)
        //{
        //    seconds = 0;
        //    chasePlayer = !chasePlayer;
        //}
        if (currentState != "chase" && fov.IsInView())
        {
            currentState = "chase";
            ai.maxSpeed  = chaseSpeed;
            stateMachine.ChangeState(EnemyChaseState.Instance);
        }
        else if (currentState != "patrol" && !fov.IsInView())
        {
            currentState = "patrol";
            ai.maxSpeed  = patrolSpeed;
            stateMachine.ChangeState(EnemyPatrolState.Instance);
        }
        ai.destination = target.position;
        stateMachine.Update();
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        //Debug.Log("Timer:"+(Time.unscaledTime - startStateTime));
        //Debug.Log(stateChangeInterval);
        //Debug.Log(Time.unscaledTime - startStateTime > stateChangeInterval);

        if (Time.unscaledTime - startStateTime > stateChangeInterval)
        {
            startStateTime = Time.unscaledTime;
            searching      = !searching;
            GoToNextState();
        }

        if (fov.IsInView() && currentState != MonsterState.KillMode)
        {
            ChangeState(MonsterState.KillMode);
        }
        ai.destination = target.position;

        stateMachine.Update();
    }