コード例 #1
0
    public void Execute()
    {
        float x = Input.GetAxis("Horizontal") * Time.deltaTime * movementSpeed;

        if (Mathf.Abs(movingBody.velocity.x) < movementSpeed / 100f && Mathf.Abs(x) > 0f)
        {
            movingBody.AddForce(new Vector2(x / 4f, 0f), ForceMode2D.Impulse);
        }
        else
        {
            if (playerController.grounded)
            {
                movingBody.velocity *= 0.9f;
            }
        }

        if (x == 0 && idlingResultsCallback != null)
        {
            secondsOfNoInput += Time.deltaTime;

            if (secondsOfNoInput >= secondsOfNoMovementBeforeIdle)
            {
                IdlingResults idlingResults = new IdlingResults(secondsOfNoMovementBeforeIdle);
                idlingResultsCallback(idlingResults);
            }
        }
    }
コード例 #2
0
ファイル: Patroller.cs プロジェクト: Bjurne/BitzBotzTechDemo
    private void StopIdling(IdlingResults idlingResults)
    {
        //Debug.Log(gameObject.name + " spent " + idlingResults.timeIdled + " seconds idling.");

        if (CheckForClearPatrollingDirection())
        {
            StartPatrolling();
        }
        else
        {
            //Debug.Log("No clear area to partoll, idling again...");
            stateMachine.ChangeState(new IdleState(5f, StopIdling));
        }
    }
コード例 #3
0
ファイル: IdleState.cs プロジェクト: Bjurne/BitzBotzTechDemo
 public void Execute()
 {
     if (timeToIdle != 0f)
     {
         if (timeSpentIdling < timeToIdle)
         {
             timeSpentIdling += Time.deltaTime;
         }
         else
         {
             var idlingResults = new IdlingResults(timeSpentIdling);
             idlingResultsCallback(idlingResults);
         }
     }
 }
コード例 #4
0
    public void Execute()
    {
        float x = Input.GetAxis("Horizontal") * Time.deltaTime * movementSpeed;

        movingBody.AddForce(new Vector2(x, 0f));

        if (x == 0 && idlingResultsCallback != null)
        {
            secondsOfNoInput += Time.deltaTime;

            if (secondsOfNoInput >= secondsOfNoMovementBeforeIdle)
            {
                IdlingResults idlingResults = new IdlingResults(secondsOfNoMovementBeforeIdle);
                idlingResultsCallback(idlingResults);
            }
        }
    }
コード例 #5
0
 public void IdlingLoopRestart(IdlingResults idlingResults)
 {
     //Debug.Log("Idle loop restarted after " + idlingResults.timeIdled + "seconds.");
     stateMachine.ChangeState(new IdleState(10f, IdlingLoopRestart));
 }