Hi everyone I am new to unity so let me know if i am missing something very basic
here is the description of the problems
dev platform : macOS
unity version : 5.5
target platform : Android and iOS
I have 4-5 quads lying on a plan in my scene so once clicked on any of the quad it plays the animations (moves up and gets bigger to hide other quads below) on the second tab it animates back to its position.
The problem is when on first click the animation is played, on second tab its registering the touch event for the quads below as well (hence triggering their animation too ). So the current workaround i found is to click on the position from where the quad original came to the big position.
Cheers.
what scripts are you using?
If you see someone who needs to know about code tags, please link them to this post: Please use code tags when posting code. You can "tag" your code by typing around your code. There is no overt "Code" tag button that automatically tags a...
Reading time: 9 mins 🕑
Likes: 83 ❤
I followed this tutorial
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class TouchInput : MonoBehaviour {
public LayerMask touchInputMask;
private List<GameObject> touchList = new List<GameObject>();
private GameObject[] touchesOld;
private RaycastHit hit;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
#if UNITY_EDITOR
// if unity editor
if (Input.GetMouseButton (0) || Input.GetMouseButtonDown (0) || Input.GetMouseButtonUp (0)) {
touchesOld = new GameObject[touchList.Count];
touchList.CopyTo (touchesOld);
touchList.Clear ();
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, out hit, touchInputMask)) {
GameObject recipient = hit.transform.gameObject;
touchList.Add (recipient);
if (Input.GetMouseButtonDown (0)) {
recipient.SendMessage ("onTouchDown", hit.point, SendMessageOptions.DontRequireReceiver);
}
if (Input.GetMouseButtonUp (0)) {
recipient.SendMessage ("onTouchUp", hit.point, SendMessageOptions.DontRequireReceiver);
}
if (Input.GetMouseButton (0)) {
recipient.SendMessage ("onTouchStay", hit.point, SendMessageOptions.DontRequireReceiver);
}
}
foreach (GameObject g in touchesOld) {
if (!touchList.Contains (g)) {
g.SendMessage ("onTouchExit", hit.point, SendMessageOptions.DontRequireReceiver);
}
}
}
#endif
if (Input.touchCount > 0) {
touchesOld = new GameObject[touchList.Count];
touchList.CopyTo (touchesOld);
touchList.Clear ();
foreach (Touch touch in Input.touches) {
Ray ray = Camera.main.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); //orignal
}
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);
}
}
}
}
}
so when the object receives “onTouchUp” msg it plays the animation and receiving same msg again it plays animation in reverse