Want to target an enemy with a button press

The problem is that when I press the button (in this case tab) it calls the function multiple times? Is there a way to only read the button press once? As of right now all I want this code to do is to print the name of the nearest enemy. It works for that, but prints 4 or times.

Code snipet:

 function OnGUI(){
    if(Input.GetButtonDown("target")){
    Debug.Log(FindClosestEnemy().name); 
    } }

Either use Update (Probably best for this), or check the EventType of the current event, to make sure you're only using it once per frame, e.g:

if (Event.current.type == EventType.Repaint && Input.GetButtonDown("target")) {

The issue is that OnGUI is called multiple times per frame for different reasons, documented int he Event Execution Order section of the manual