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

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);
}