123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- 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 accelerationLoss = 0.5f;
- 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 * Time.deltaTime;
- }
- [UsedImplicitly]
- public void OnSpeed(InputValue value)
- {
- acceleration = value.Get<float>() * speedMultiplier;
- if (acceleration < 0.1f && acceleration >= 0) acceleration = -accelerationLoss;
- }
- [UsedImplicitly]
- public void OnLean(InputValue value)
- {
- lean = value.Get<float>() * leanMultiplier;
- }
- [UsedImplicitly]
- public void OnSteer(InputValue value)
- {
- steer = value.Get<float>() * steerMultiplier;
- }
- }
- }
|