Hello everyone,
I am creating a script to accelerate bike as long as Player Holding Space Button and Stop bike when player release button. I am using new Input System and finding it really difficult to create this simple thing. I succeed to create this script, where, when player hold space button bike start acceleration but I have no idea how to stop bike when space button released:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class RotateRearWheel : MonoBehaviour
{
public JointMotor2D motor;
private InputActionAsset controls;
void Awake()
{
controls = new InputActionAsset();
}
void OnEnable()
{
controls.Enable();
}
void OnDisable()
{
controls.Disable();
}
public void OnSpace(InputValue value)
{
var hinge = GetComponent<HingeJoint2D>();
var motor = hinge.motor;
motor.motorSpeed = 200;
hinge.motor = motor;
hinge.useMotor = true;
}
}
Please help me on completing this code.