Quantcast
Channel: Latest Questions by alexkaskasoli
Viewing all articles
Browse latest Browse all 56

If button held 3 seconds do something

$
0
0
I'm trying to do a Crouch/Lay down system: 1) Press C => crouch 2) Hold C for 3 seconds => lay down The logical way to do this seemed to be to use a timer: if (Input.GetButtonDown ("Crouch")) { print("Crouch"); if (crouching) Stand(); else Crouch(); // Start Timer timer = new Timer(crouchDelay); timer.Elapsed += new ElapsedEventHandler(CrouchTimer); timer.Enabled = true; } else if (Input.GetButtonUp ("Crouch")) { timer.Enabled = false; } But this isn't working, getting timers to work in unity has proven to be a real pain the £$%. In this case the method CrouchTimer() is always called instantly, no matter what value crouchDelay has. If you wanted to call a method ONLY if a key was held for 3 seconds, how would you do it?

Viewing all articles
Browse latest Browse all 56

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>