1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using JetBrains.Annotations;
- using UnityEngine;
- using UnityEngine.InputSystem;
- [RequireComponent(typeof(PlayerInput))]
- [RequireComponent(typeof(BicycleController))]
- 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 speed;
- private float lean;
- private float steer;
- private BicycleController bicycleController;
-
- private void Start()
- {
- bicycleController = GetComponent<BicycleController>();
- }
-
- private void Update()
- {
- if(useSteer) bicycleController.CurrentSteerAngle = steer;
- if(useLean) bicycleController.CurrentLeaningAngle = lean;
- if (useSpeed)
- {
- if (speed < 0)
- {
- bicycleController.CurrentMotorTorque = 0;
- bicycleController.CurrentBrakeTorque = -speed;
- }
- else
- {
- bicycleController.CurrentBrakeTorque = 0;
- bicycleController.CurrentMotorTorque = speed;
- }
- }
- }
-
- [UsedImplicitly]
- public void OnSpeed(InputValue value)
- {
- speed = 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;
- }
- }
|