Create 'Shortcut' In C#
I don't remember what its called but I remember doing it somewhere.
I want to set a 'shortcut' for specific code so I dont have to type it out every time I need it.
Ex: string dbug = Debug.Log();
or: string gkdown = Input.GetKeyDown;
with the gkdown i could do if(gkdown(keycode.W){//Code}
Answer by hexagonius · Apr 05, 2017 at 06:11 AM
you mean delegates.
System.Action<string> dbug = Debug.Log;
System.Action<KeyCode> gkdown = Input.GetKeyDown;
Answer by UnityCoach · Apr 05, 2017 at 06:09 AM
It's called teamplates or snippets. In MonoDevelop, you'll find it under Text Editor / Code Templates in the Preferences.
Answer by Ryebread5 · Apr 05, 2017 at 06:50 AM
I get an error for the KeyCode one and don't know what it means
A method or delegate 'bool UnityEngine.Input.GetKeyDown(UnityEngine.KeyCode)' return type does not match delegate 'void System.Action(UnityEngine.KeyCode)' return type
I didn't see anything like what hexagonius said in the code templates
Edit: Or do you mean to create my own snippet thing?
I'm not sure what you meant. Templates are shortcut to quickly lay some code. Like, for example, you can type "property", hit tab twice, and you have
private type _name;
public type name {get; set;}
If what you want is to type gkdown anywhere ins$$anonymous$$d of Input.Get$$anonymous$$eyDown, well, you'll end up with code no-one but you can read..
I don't $$anonymous$$d having noone able to read my code since i'm the only one that needs it unless I ask for help in which case I can use the actual code for whats needed.
But yes I want to be able to use the gkdown in replacement of the Input.Get$$anonymous$$eyDown
Then maybe you can create your own custom methods like :
public bool gkdown ($$anonymous$$eycode keycode)
{
return Input.Get$$anonymous$$eyDown (keycode);
}