Answers for "OnMouseDown for mobile in unity"

C#
1

OnMouseDown for mobile in unity

bool dragBool;

//On PC (instead of)
	void OnMouseDown() {
    	//The start
    	dragBool = true;
    }
    void OnMouseUp() {
    	//The Finish
        dragBool = false;
    }
    
//On mobile (do this)
	void Update() {
    	if(Input.touchCount == 1) {
        	if(Input.GetTouch(0).phase == TouchPhase.Began)
            	dragBool = true;
            else if(Input.GetTouch(0).phase == TouchPhase.Ended)
            	dragBool = false;
        }
    }
    
//When the dragBool is true it means the touch of the player starts 
//And when is false it means it stops
Posted by: Guest on August-02-2021

C# Answers by Framework

Browse Popular Code Answers by Language