Hello all,
I am trying to make a variable based script for my vehicular based game. As i’m making a simulator I need/would like a Engine variable for when the engine is either “on” or “off”. To do this I have used:
public float engine;
and
void Start () {
engine = 0;
}
To control the variable. For the button input I am using:
if(Input.GetKey(KeyCode.E)){
if(engine == 0)
engine = 1;
else
engine = 0;
}
Yet this method only works the first time “E” is pressed then it requires two quick presses if not more. Is there a better solution which works all the time?
Many Thanks,
~James W
you need to use getkeydown, geykey will only work for the time you keep pressing.
– ozturkcompanyThanks for the fast reply @ozturkcompany your solution worked but tanoshimi wrote that as an answer which I could accept.
– James_Wassallhi no problem at all :) cheers
– ozturkcompany