I don’t understand why this doesn’t work
var timer1;
var holdtime;
if (Input.GetKeyUp(KeyCode.W) && timer1 > holdtime) {}
Unity keeps telling me that I cant use this symbol (>) between the object and the float.
Also I wouldn’t mind making it a greater than or equal to rather than just greater than if that is possible.
I know this is a noobie question but I am new and cant find any answers.
If you’re using C# (and it looks like you are), I recommend exorcising the ‘var’ keyword from your code. When ‘var’ is forbidden, code is much easier to debug, in my experience. Strong-typed languages can save you headaches!
Also, make sure to initialize your variables. Rather than just declaring them, give them a starting value, even if it’s just zero. It increases code readability.
I’m surprised you can use var
without assigning it any value.
Like @FortisVenaliter said, type your variables, it’ll make it easier. You can use >=
or <=
for greater/less than or equal to.
float timer1;
float holdtime;
if (Input.GetKeyUp(KeyCode.W) && timer1 >= holdtime)