How to hold button - LongPress?

Ask for help and post bugs.

How to hold button - LongPress?

Postby guicamarotto » Sat Jul 18, 2015 1:00 am

Hi all. I have downloaded the TouchScript asset today and implement the simple tap on my 2D sprite buttons (not ui). but I want to hold a button, like shoot button, to continuous shooting. I write this code but theres an error on the State property. unity dont recognize it.

Code: Select all
using System;
using TouchScript;
using TouchScript.Gestures;
using UnityEngine;

public class ButtonShoot : MonoBehaviour {
   public Rigidbody2D projectile;
   public Transform gun;

   public float fireRate = 0.5f;
   private float nextFire = 0.0f;

   private void OnEnable()
      // subscribe to gesture's Tapped event
      GetComponent<TapGesture>().Tapped += tappedHandler;
      GetComponent<LongPressGesture>().StateChanged += holdHandler;
   private void OnDisable()
      // don't forget to unsubscribe
      GetComponent<TapGesture>().Tapped -= tappedHandler;
      GetComponent<LongPressGesture>().StateChanged -= holdHandler;

   private void tappedHandler(object sender, EventArgs e)
      Shoot ();

   private void holdHandler(object sender, EventArgs e)
      switch (e.State)
      case Gesture.GestureState.Recognized:
      case Gesture.GestureState.Failed:
      case Gesture.GestureState.Cancelled:
         //Do your action if CANCEL LONG PRESS
      if (e.State == Gesture.GestureState.Recognized)
   void Shoot(){
      if (Time.time > nextFire) {
         nextFire = Time.time + fireRate;
         Rigidbody2D laser;
         laser = Instantiate (projectile, gun.position, gun.rotation) as Rigidbody2D;
         laser.velocity = transform.TransformDirection (Vector2.right * 10);
         Destroy (laser.gameObject, 1);

can anyone help me please
Posts: 1
Joined: Sat Jul 18, 2015 12:32 am

Return to Help and Bugs

Who is online

Users browsing this forum: Bing [Bot] and 2 guests