Advertisement
Guest User

Input Controller - Virus Remover - Nick Peelman

a guest
Jul 22nd, 2014
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class InputController : MonoBehaviour {
  5.  
  6.     private FingerInput fi;
  7.     //caching
  8.     private Touch touch;
  9.     private int touchCount;
  10.  
  11.     private enum FingerInput
  12.     {
  13.         None,
  14.         OneBegin,
  15.         Two,
  16.         OneEnd,
  17.     };
  18.  
  19.     void Awake()
  20.     {
  21.         fi = FingerInput.None;
  22.     }
  23.  
  24.     void Update ()
  25.     {
  26.         //Debug.Log (fi);
  27.  
  28.         for(int i = 0; i < Input.touchCount; i++)
  29.         {
  30.             touch = Input.GetTouch(i);
  31.             touchCount = Input.touchCount;
  32.  
  33.             if(touch.phase == TouchPhase.Began)
  34.             {
  35.                 if(touchCount == 1)//One finger down
  36.                 {
  37.                     if(fi == FingerInput.None)//if none were down before this input, then it's the first.
  38.                     {
  39.                         fi = FingerInput.OneBegin;
  40.                         //charge circle and attract virus'!
  41.                         Vector3 touchPos = touch.position;
  42.                         //touchPos.z = -10;
  43.  
  44.                         VirusController.AllChasePlayer(camera.ScreenToWorldPoint(touchPos));
  45.                         Debug.Log(camera.ScreenToWorldPoint(touchPos));
  46.                     }
  47.                     if(fi == FingerInput.Two)//if 2 were down before this input, it's the end finger.
  48.                     {
  49.                         fi = FingerInput.OneEnd;
  50.                     }
  51.                 }
  52.                 else if(touchCount == 2)// 2 fingers down
  53.                 {
  54.                     if(fi == FingerInput.OneBegin)//only go to the 2 fingers down (aka charge the circle) when it's the first input!
  55.                     {
  56.                         fi = FingerInput.Two;
  57.                     }
  58.                 }
  59.             }
  60.             if(touch.phase == TouchPhase.Ended)
  61.             {
  62.                 if(touchCount == 2)//endfinger state when one of 2 fingers is gone
  63.                     fi = FingerInput.OneEnd;
  64.                 if(touchCount == 1)//no fingers
  65.                 {
  66.                     fi = FingerInput.None;
  67.                     VirusController.AllIdle();
  68.                 }
  69.             }
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement