Problem with Input.GetMouseButtonUp(0) being executed twice

Problem Description

Through Unity Input.GetMouseButtonDown, the mouse is detected and two press events occur with one click.

if (Input.GetMouseButtonDown(0))
{
    
    
    Debug.LogError("GetMouseButtonDown");

}

file

Solution

Control a click through the up variable

 bool isUp = true;
 bool isDown = false;

 bool IsButtonClick()
 {
    
    

     if (Input.GetMouseButtonUp(0) && isDown)
     {
    
    
         Debug.LogError("isUp");
         isUp = true;
     }

     if (Input.GetMouseButtonDown(0) && isUp)
     {
    
    
         Debug.LogError("isDown");
         isUp = false;
         isDown = true;
     }
     return false;
 }

file

Guess you like

Origin blog.csdn.net/euphorias/article/details/127791807