protected void randomInput()
    {
        if (sinceLastDecision > decisionCadence)
        {
            bool positionChange = Random.Range(0.0f, 1.0f) < stateChangeProbability;
            if (positionChange)
            {
                inputBroker.clearInputs();
                float randomAxis = Random.Range(0.0f, 1.0f);
                if (randomAxis < axisProbability)   // left
                {
                    verticalPressDuration = 0.0f;
                    if (!inputBroker.HorizontalPressed())
                    {
                        inputBroker.setHorizontal(-1.0f);
                    }
                    else
                    {
                        inputBroker.setHorizontal(0.0f);
                    }
                }
                else if (randomAxis < (2 * axisProbability))     // right
                {
                    verticalPressDuration = 0.0f;
                    if (!inputBroker.HorizontalPressed())
                    {
                        inputBroker.setHorizontal(1.0f);
                    }
                    else
                    {
                        inputBroker.setHorizontal(0.0f);
                    }
                }
                else     // down
                {
                    horizontalPressDuration = 0.0f;
                    if (!inputBroker.VerticalPressed())
                    {
                        inputBroker.setVertical(-1.0f);
                    }
                    else
                    {
                        inputBroker.setVertical(0.0f);
                    }
                }
            }
            sinceLastDecision = 0.0f;
        }

        if (horizontalPressDuration > maxPressDuration)
        {
            inputBroker.setHorizontal(0.0f);
            sinceLastDecision = 0.0f;
        }
        if (verticalPressDuration > maxPressDuration)
        {
            inputBroker.setVertical(0.0f);
            sinceLastDecision = 0.0f;
        }
    }
예제 #2
0
    protected void randomInput()
    {
        if (sinceLastDecision > decisionCadence)
        {
            bool horizontalChange = Random.Range(0.0f, 1.0f) > stateChangeProbability;
            if (horizontalChange)
            {
                if (!inputBroker.HorizontalPressed())
                {
                    inputBroker.setHorizontal(Random.Range(-1.0f, 1.0f));
                }
                else
                {
                    inputBroker.setHorizontal(0.0f);
                }
            }
            bool verticalChange = Random.Range(0.0f, 1.0f) > stateChangeProbability;
            if (verticalChange)
            {
                if (!inputBroker.VerticalPressed())
                {
                    inputBroker.setVertical(Random.Range(-1.0f, 1.0f));
                }
                else
                {
                    inputBroker.setVertical(0.0f);
                }
            }
            sinceLastDecision = 0.0f;
        }

        if (horizontalPressDuration > maxPressDuration)
        {
            inputBroker.setHorizontal(0.0f);
            sinceLastDecision = 0.0f;
        }
        if (verticalPressDuration > maxPressDuration)
        {
            inputBroker.setVertical(0.0f);
            sinceLastDecision = 0.0f;
        }
    }
 void Update()
 {
     sinceLastDecision += Time.deltaTime;
     if (InputBroker.HorizontalPressed())
     {
         horizontalPressDuration += Time.deltaTime;
     }
     else
     {
         horizontalPressDuration = 0;
     }
     if (InputBroker.VerticalPressed())
     {
         verticalPressDuration += Time.deltaTime;
     }
     else
     {
         verticalPressDuration = 0;
     }
 }