Skip to content

Instantly share code, notes, and snippets.

@davemo
Created April 30, 2012 18:08
Show Gist options
  • Select an option

  • Save davemo/2560552 to your computer and use it in GitHub Desktop.

Select an option

Save davemo/2560552 to your computer and use it in GitHub Desktop.
A simple way to add Behaviour to a GUITexture in Unity3D on a Swipe Touch event using the FingerGestures plugin.
using UnityEngine;
using System.Collections;
public class Swiper : MonoBehaviour {
public GameObject appController; // some controller object that handles your app behaviour
public GUITexture swipeObject; // the GUITexture you want to add swipe behaviour to
// Note: this relies on the slick little FingerGestures library on the Unity Asset Store: http://u3d.as/content/william-ravaine/finger-gestures/21Z
void OnEnable() {
FingerGestures.OnFingerSwipe += FingerGestures_OnFingerSwipe;
}
void OnDisable() {
FingerGestures.OnFingerSwipe -= FingerGestures_OnFingerSwipe;
}
void FingerGestures_OnFingerSwipe( int fingerIndex, Vector2 startPos, FingerGestures.SwipeDirection direction, float velocity ) {
if(swipeObject.HitTest(startPos)) {
if(direction == FingerGestures.SwipeDirection.Left) {
// in AppController.cs you can implement the behaviour, or just do it here
appController.SendMessage("doSomethingLeft");
}
if(direction == FingerGestures.SwipeDirection.Right) {
// in AppController.cs you can implement the behaviour, or just do it here
appController.SendMessage("doSomethingRight");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment