示例#1
0
 private void KeepDesiredSpeed()
 {
     if (NeedsAcceleration())
     {
         vehicle.Accelerate();
     }
     else if (NeedsBraking())
     {
         vehicle.Brake();
     }
 }
    // Update is called once per frame
    void Update()
    {
        VehicleAgent vehicle = gameObject.GetComponent <VehicleAgent> ();

        if (Input.GetKey(forwardKey))
        {
            vehicle.Accelerate();
        }

        if (Input.GetKey(backwardKey))
        {
            vehicle.Brake();
        }

        if (Input.GetKey(leftKey))
        {
            vehicle.SteerLeft();
        }

        if (Input.GetKey(rightKey))
        {
            vehicle.SteerRight();
        }
    }