Skip to content

Instantly share code, notes, and snippets.

@keithweaver
Created March 27, 2017 14:00
Show Gist options
  • Save keithweaver/7da0247b0a9551d8b456396d37755ad7 to your computer and use it in GitHub Desktop.
Save keithweaver/7da0247b0a9551d8b456396d37755ad7 to your computer and use it in GitHub Desktop.
Handle touch input or mouse click with Unity
// Example of handling click or touch down in Unity
using System.Collections;
using System.Collections.Generic;
using Unity;
public class CharacterMovement : MonoBehaviour {
void start() {
Debug.Log("Start");
}
void update() {
if (Input.touchCount > 0 || Input.GetMouseButtonDown(0)) {
// Either touch down or Mouse click
Debug.Log("Explosion");
}
}
}
@TTx125
Copy link

TTx125 commented Dec 13, 2019

I tested it on android (one click add one shot) and it continuously add shot. As "Input.GetMouseButtonDown(0)" work in android, you can remove "Input.touchCount > 0 ||" from =the condition and now it will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment