I made Ui for controlling my Player, all is fine , but i have methods that work when i press F on my keyboard , how can I make my button equals to keycode.F ? like when I press the button it types F ? please help , i donât want it in If statement âIf(input.getkeydown(keycode.F)â i donât want this , i tried to make input.getkeydown(keycode.F) and that doesnât work i couldnât access the F keyCode.
Change the condition in the if statement to:
bool allowObjMovement = false;
void Update()
{
if(input.getkey(keycode.F))
allowObjMovement = true;
}
Void OnTrigger2D(Colllider2D other)
{
if player.collider...etc && allowObjMovement == true;
{
do something.
}
}
Now for the UI Button try this or set allowObjMovement to true however you want.
Personally, I think youâd be better off using the Input system. If you define an Input called âPushâ and set that input to KeyPress F, you can also assign it to a gamepad button, or Mouse Button 3. The input system works better than specifically defining a key, and it allows the user to remap it in case they donât want to use âFâ. Not that the other answers are incorrect, or even less correct.
Just my two cents.
@hexagonius itâs not a method , when ever my player collides with something and press F i can move the thing the player colides with around .something like :
Void OnTrigger2D(Colllider2D other){
if player.colliderâŚetc && input.getkeydown(keycode.F){
do something.
}
}