- Home /
Can an Input event be 'faked' with a script?
You know how you can use the Input Manager to define an event like "Jump" which the user can assign to a key? Is there a way to then programmatically create a "Jump" event? I know I could call the appropriate functions directly, but if these events are handled in several script or ones I'd rather not muck with, it seems like faking events might be cleaner.
Specifically, I want to make some on-screen buttons that mimic keyboard buttons, so pressing the mouse over the on-screen 'left arrow' key would do the same thing as pressing the actual left arrow key.
Dave, did you ever figure out a way to do this? In one gamestate, one script is intentionally ignoring input, but I wish to (occasionally) fake input that's specific to what's actually been pressed. If this is too obscure, I may just post a new question...
Answer by Eric5h5 · Feb 19, 2011 at 01:09 AM
Just abstract it:
function Update () { if (Jump()) { // do jumping } }
private var doJump = false;
function Jump () : boolean { if (Input.GetButtonDown("Jump")) { return true; } if (doJump) { doJump = false; return true; } return false; }
function DoJump () { doJump = true; }
Then call DoJump when an on-screen jump button is clicked or when you want to "fake" it. If you have jump input handled in more than one place, always call the Jump function instead of checking input directly.