123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- using Controller.Bicycle;
- using UnityEngine;
- namespace Controller
- {
- [RequireComponent(typeof(IBicycleController))]
- public class KeyboardBikeController : MonoBehaviour
- {
- private IBicycleController bicycleController;
- 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()
- {
- bicycleController = GetComponent<IBicycleController>();
- }
- private void Update()
- {
- if (accelerate)
- {
- if (Input.GetKey(KeyCode.T))
- {
- bicycleController.CurrentSpeed += speedIncreasePerSecond * Time.deltaTime;
- }
- else if (bicycleController.CurrentSpeed > 0)
- {
- bicycleController.CurrentSpeed = Mathf.Max(0,
- bicycleController.CurrentSpeed - speedDecreasePerSecond * Time.deltaTime);
- }
- if (Input.GetKey(KeyCode.G))
- {
- bicycleController.CurrentSpeed = Mathf.Max(0,
- bicycleController.CurrentSpeed - brakeIncreasePerSecond * Time.deltaTime);
- }
- }
- if (steer)
- {
- if (Input.GetKey(KeyCode.F))
- {
- bicycleController.CurrentSteerAngle -= steeringAngleIncreasePerSecond * Time.deltaTime;
- }
- if (Input.GetKey(KeyCode.H))
- {
- bicycleController.CurrentSteerAngle += steeringAngleIncreasePerSecond * Time.deltaTime;
- }
- if (Input.GetKeyUp(KeyCode.F) || Input.GetKeyUp(KeyCode.H))
- {
- bicycleController.CurrentSteerAngle = 0f;
- }
- }
- if (lean)
- {
- if (Input.GetKey(KeyCode.R))
- {
- bicycleController.CurrentLeaningAngle -= leaningAngleIncreasePerSecond * Time.deltaTime;
- }
- if (Input.GetKey(KeyCode.Z))
- {
- bicycleController.CurrentLeaningAngle += leaningAngleIncreasePerSecond * Time.deltaTime;
- }
- if (Input.GetKeyUp(KeyCode.R) || Input.GetKeyUp(KeyCode.Z))
- {
- bicycleController.CurrentLeaningAngle = 0f;
- }
- }
- }
- }
- }
|