Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class inputTouch : MonoBehaviour {
- public LayerMask touchInputMask;
- private List<GameObject> touchList = new List<GameObject> ();
- private GameObject[] touchesOld;
- private RaycastHit hit;
- // Update is called once per frame
- void Update () {
- #if UNITY_EDITOR
- #endif
- if (Input.touchCount > 0) {
- touchesOld = new GameObject[touchList.Count];
- touchList.CopyTo (touchesOld);
- touchList.Clear ();
- foreach (Touch touch in Input.touches) {
- Ray ray = GetComponent<Camera> ().ScreenPointToRay (touch.position);
- if (Physics.Raycast (ray, out hit, touchInputMask)) {
- GameObject recipient = hit.transform.gameObject;
- touchList.Add (recipient);
- if (touch.phase == TouchPhase.Began) {
- recipient.SendMessage ("OnTouchDown", hit.point, SendMessageOptions.DontRequireReceiver);
- }
- if (touch.phase == TouchPhase.Ended) {
- recipient.SendMessage ("OnTouchUp", hit.point, SendMessageOptions.DontRequireReceiver);
- }
- if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved) {
- recipient.SendMessage ("OnTouchStay", hit.point, SendMessageOptions.DontRequireReceiver);
- }
- if (touch.phase == TouchPhase.Canceled) {
- recipient.SendMessage ("OnTouchExit", hit.point, SendMessageOptions.DontRequireReceiver);
- }
- }
- }
- foreach (GameObject g in touchesOld) {
- if (!touchList.Contains(g)){
- g.SendMessage ("OnTouchExit", hit.point, SendMessageOptions.DontRequireReceiver);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement