- Home /
Question by
Chimaera987 · Apr 28, 2019 at 09:04 AM ·
scripting problemscripting beginnercarbuttonscar physics
Value chages when button is held down, but after release it reverts to old value.
So I have this transmission script that I wrote. It works fine, changes the gear and gets that gears gear ratio. When I shift up/down the gear changes, but as soon as I release the said button it falls back to the previous gear. Input.GetButtonUp/Down don't work at all, no idea why. Here's the script:
public enum TransmissionType { Manual, Automatic }
public TransmissionType transmissionType = TransmissionType.Manual;
public Gear[] gears;
public int firstGear;
public int currentGear;
public float curGearRatio;
// Start is called before the first frame update
void Start()
{
for (int i = 0; i < gears.Length; i++)
{
if (gears[i].ratio == 0)
{
firstGear = i + 1;
break;
}
}
}
// Update is called once per frame
void FixedUpdate()
{
currentGear = Mathf.Clamp(firstGear, 0, gears.Length - 1);
if (transmissionType == TransmissionType.Manual)
{
if (Input.GetButton("Upshift"))
{
currentGear++;
}
if (Input.GetButton("Downshift"))
{
currentGear--;
}
}
curGearRatio = gears[currentGear].ratio;
}
[System.Serializable]
public class Gear
{
public float ratio;
}
Comment