1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using Controller.Bicycle;
- using UnityEngine;
- namespace Controller
- {
- public class KeyboardBikeController : MonoBehaviour
- {
- private WcBicycleController wcBicycleController;
- public bool steer = true;
- public bool lean = true;
- public bool accelerate = true;
- public float speedIncreasePerSecond = 3f;
- public float speedDecreasePerSecond = 0.5f;
- public float brakeIncreasePerSecond = 5f;
- public float leaningAngleIncreasePerSecond = 2f;
- public float steeringAngleIncreasePerSecond = 2.5f;
- private void Start()
- {
- wcBicycleController = GetComponent<WcBicycleController>();
- }
- private void Update()
- {
- if (accelerate)
- {
- if (Input.GetKey(KeyCode.T))
- {
- wcBicycleController.CurrentSpeed += speedIncreasePerSecond * Time.deltaTime;
- }
- else if (wcBicycleController.CurrentSpeed > 0)
- {
- wcBicycleController.CurrentSpeed = Mathf.Max(0,
- wcBicycleController.CurrentSpeed - speedDecreasePerSecond * Time.deltaTime);
- }
- if (Input.GetKey(KeyCode.G))
- {
- wcBicycleController.CurrentSpeed = Mathf.Max(0,
- wcBicycleController.CurrentSpeed - brakeIncreasePerSecond * Time.deltaTime);
- }
- }
- if (steer)
- {
- if (Input.GetKey(KeyCode.F))
- {
- wcBicycleController.CurrentSteerAngle -= steeringAngleIncreasePerSecond * Time.deltaTime;
- }
- if (Input.GetKey(KeyCode.H))
- {
- wcBicycleController.CurrentSteerAngle += steeringAngleIncreasePerSecond * Time.deltaTime;
- }
- if (Input.GetKeyUp(KeyCode.F) || Input.GetKeyUp(KeyCode.H))
- {
- wcBicycleController.CurrentSteerAngle = 0f;
- }
- }
- if (lean)
- {
- if (Input.GetKey(KeyCode.R))
- {
- wcBicycleController.CurrentLeaningAngle -= leaningAngleIncreasePerSecond * Time.deltaTime;
- }
- if (Input.GetKey(KeyCode.Z))
- {
- wcBicycleController.CurrentLeaningAngle += leaningAngleIncreasePerSecond * Time.deltaTime;
- }
- if (Input.GetKeyUp(KeyCode.R) || Input.GetKeyUp(KeyCode.Z))
- {
- wcBicycleController.CurrentLeaningAngle = 0f;
- }
- }
- }
- }
- }
|