12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- using Controller.Bicycle;
- using JetBrains.Annotations;
- using UnityEngine;
- using UnityEngine.InputSystem;
- namespace Controller
- {
- [RequireComponent(typeof(PlayerInput))]
- [RequireComponent(typeof(IBicycleController))]
- public class GamepadBikeController : MonoBehaviour
- {
- public bool useSpeed;
- public bool useSteer;
- public bool useLean;
- public float speedMultiplier = 200f;
- public float leanMultiplier = 20f;
- public float steerMultiplier = 15f;
- private float acceleration;
- private float lean;
- private float steer;
- private IBicycleController bicycleController;
- private void Start()
- {
- bicycleController = GetComponent<IBicycleController>();
- }
- private void Update()
- {
- if (useSteer) bicycleController.CurrentSteerAngle = steer;
- if (useLean) bicycleController.CurrentLeaningAngle = lean;
- if (useSpeed) bicycleController.CurrentSpeed += acceleration;
- }
- [UsedImplicitly]
- public void OnSpeed(InputValue value)
- {
- acceleration = value.Get<float>() * speedMultiplier;
- }
- [UsedImplicitly]
- public void OnLean(InputValue value)
- {
- lean = value.Get<float>() * leanMultiplier;
- }
- [UsedImplicitly]
- public void OnSteer(InputValue value)
- {
- steer = value.Get<float>() * steerMultiplier;
- }
- }
- }
|