Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- class StickyInput {
- KeyCode keycode;
- // duration after key press that key should behave as if being repeatedly pressed
- float stickyTime;
- float stickyEndTime;
- public StickyInput(KeyCode keycode, float stickyTime) {
- this.keycode = keycode;
- this.stickyTime = stickyTime;
- }
- public bool GetKeyDown() {
- bool realKeyPress = Input.GetKeyDown(keycode);
- if (realKeyPress) {
- stickyEndTime = Time.time + stickyTime;
- }
- return realKeyPress || Time.time < stickyEndTime;
- }
- public bool GetKeyUp() {
- return Input.GetKeyUp(keycode);
- }
- public bool GetKey() {
- return Input.GetKey(keycode);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement