- Home /
Use Input.GetKeyDown as a function?
Hi, im really stuck.
I have some code that contains a 'if(Input.GetKeyDown("c"))'
I was using that as a test controller for my script, but what i really need is for this to be replaced with something that can be called by another script.
But have the same output effect as this if with GetKey, that or a means of having it for if i click on a collider (that is a separate gameobject.)
Really would appreciate your help,
Thanks, - Graeme
Basicly, that i need to find some way of simulating Get$$anonymous$$eyDown, or something with the same effect. Through a function call.
i tried using a boolean that went on and then off, but that made a mess of things...
Answer by aldonaletto · Aug 29, 2011 at 01:32 PM
Save this script as Fake.js. Whenever you want to check the input, use Fake.GetKeyDown("c") instead of Input.GetKeyDown("c"). To set the output as if the key was pressed, just set the variable Fake.keyDown to true (it will be automatically set to false after reading):
static var keyDown = false;
static function GetKeyDown(key: String): boolean { if (keyDown){ keyDown = false; return true; } else return Input.GetKeyDown(key); }
Your answer
Follow this Question
Related Questions
Problem With else if statement 1 Answer
Input.GetKeyDown and OnTriggerEnter problem. 2 Answers
Update GetKey If Statements both playing instantly 1 Answer
Change view if key is pressed 4 Answers