Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class InputController : MonoBehaviour {
- private FingerInput fi;
- //caching
- private Touch touch;
- private int touchCount;
- private enum FingerInput
- {
- None,
- OneBegin,
- Two,
- OneEnd,
- };
- void Awake()
- {
- fi = FingerInput.None;
- }
- void Update ()
- {
- //Debug.Log (fi);
- for(int i = 0; i < Input.touchCount; i++)
- {
- touch = Input.GetTouch(i);
- touchCount = Input.touchCount;
- if(touch.phase == TouchPhase.Began)
- {
- if(touchCount == 1)//One finger down
- {
- if(fi == FingerInput.None)//if none were down before this input, then it's the first.
- {
- fi = FingerInput.OneBegin;
- //charge circle and attract virus'!
- Vector3 touchPos = touch.position;
- //touchPos.z = -10;
- VirusController.AllChasePlayer(camera.ScreenToWorldPoint(touchPos));
- Debug.Log(camera.ScreenToWorldPoint(touchPos));
- }
- if(fi == FingerInput.Two)//if 2 were down before this input, it's the end finger.
- {
- fi = FingerInput.OneEnd;
- }
- }
- else if(touchCount == 2)// 2 fingers down
- {
- if(fi == FingerInput.OneBegin)//only go to the 2 fingers down (aka charge the circle) when it's the first input!
- {
- fi = FingerInput.Two;
- }
- }
- }
- if(touch.phase == TouchPhase.Ended)
- {
- if(touchCount == 2)//endfinger state when one of 2 fingers is gone
- fi = FingerInput.OneEnd;
- if(touchCount == 1)//no fingers
- {
- fi = FingerInput.None;
- VirusController.AllIdle();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement