- Home /
Unity double tap explanation
This is the code given by Unity docs for a double tap that makes a projectile. I would like to learn how this code works and if possible, how I can edit it even further, for example, make it a single tap instead of a double tap. Thanks
var projectile : GameObject;
function Update () {
for (var i = 0; i < Input.touchCount; ++i) {
if (Input.GetTouch(i).phase == TouchPhase.Began) {
clone = Instantiate (projectile, transform.position, transform.rotation);
I think you can use http://docs.unity3d.com/ScriptReference/Input-touchCount.html
Answer by Graham-Dunnett · Sep 08, 2014 at 10:58 AM
The code you post (copied from the docs for Input.GetTouch
) does not require a double tap. The example looks to see if any touch has started, and fires the projectile. Most mobile devices support multi-touch, and the for()
loop looks at each of the touches. There is a way to detect a double tap, and that's to use:
Actually, the script I posted supports double tap as well, but what I'm looking for is a way to edit this so it can it works with a single tap, NOT double tap. From there, I can make other edits, but I can't do that if the only thing I'm looking at is var tapCount: int; There is no explanation for what to do with this
Your answer
Follow this Question
Related Questions
How is "Touch.tapCount" bounded? 1 Answer
touch game objects on ios 1 Answer
Detect a tap versus standing touch on iPhone? 3 Answers
Remove Y-axis clamp from Tap to Move, Drag to Look Script 0 Answers
OnMouseDown works fine for iOS 2 Answers