Hey everyone, I'm build a navigation app and currently right now I have a problem on my Map screen. There are 4 sprites in the scene, these sprites take up the mass majority of the scene. So to best explain my problem through text.. You know how on your phone, you to a view your contacts and you scroll through many contacts in there. But if you noticed, the buttons arrent being activated. Or if you sometimes hold your finger over some place and drag it over a button, the button will not be activated until you let go and then tap the button. In This case it is exactly the opposite. I believe its called ghost touching or something like that, When I'm moving and my finger is over a button, the button thinks I'm click when really I'm not. Here are my scripts. My mobile movement Code (JavaScript): #pragma strict var zoomSpeed : float = 0.5f; var maxZoom : float = 0.0f; var minZoom : float = 0.0f; private var fingerPos : Vector2 = Vector2.zero; private var lastPos : Vector2 = Vector2.zero; private var movedBy : Vector2 = Vector2.zero; private var xPos : float = 0.0f; private var yPos : float = 0.0f; var sensitivity : float = 3.0f; var maximumX : float = 0.0f; var minumumX : float = 0.0f; var maximumY : float = 0.0f; var minumumY : float = 0.0f; private var zoom = false; private var foto : Camera; var usesIndicator = false; var identifer : GameObject; var indicator : GameObject; var tap : float = 0.0f; function Awake () { foto = GetComponent(Camera); if(usesIndicator){ identifer.SetActive(false); indicator.SetActive(false); } transform.position = Vector3(Mathf.Clamp(transform.position.x, maximumX, minumumX), Mathf.Clamp(transform.position.y, maximumY, minumumY), transform.position.z);//clamp x } function LateUpdate () { if (Input.touchCount == 1){ var touch : Touch = Input.GetTouch(0); if(touch.phase == TouchPhase.Began){ fingerPos = Vector2.zero; lastPos = Vector2.zero; movedBy = Vector2.zero; xPos = 0; yPos = 0; tap = 1; fingerPos = touch.position; zoom = true; if(usesIndicator){ identifer.SetActive(true); indicator.SetActive(true); } } else if(touch.phase == TouchPhase.Moved){ movedBy = touch.position - fingerPos; lastPos = fingerPos; fingerPos = touch.position; xPos = movedBy.x / Screen.width; yPos = movedBy.y / Screen.width; zoom = false; tap = 1; } else if(touch.phase == TouchPhase.Stationary){ lastPos = fingerPos; fingerPos = touch.position; xPos = 0; yPos = 0; zoom = true; tap = 1; } else if(touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled){ xPos = 0; yPos = 0; zoom = true; tap = 0; } } transform.position += Vector3(-xPos * sensitivity, -yPos * sensitivity, 0.0f); if(Input.touchCount == 2 && zoom == true){ var fingerOne = Input.GetTouch(0); var fingerTwo = Input.GetTouch(1); var lastOnePos = fingerOne.position - fingerOne.deltaPosition; var lastTwoPos = fingerTwo.position - fingerTwo.deltaPosition; var lastMag = (lastOnePos - lastTwoPos).magnitude; var deltaMag = (fingerOne.position - fingerTwo.position).magnitude; var magDiff = lastMag - deltaMag; foto.orthographicSize += magDiff * zoomSpeed; foto.orthographicSize = Mathf.Clamp(foto.orthographicSize, minZoom, maxZoom); } } My buttons script Code (JavaScript): #pragma strict var cam : Camera; var selectedCol : Color; var camZoom : float = 0.0f; var level : String; var mobilemove : MobileMovement; var loadingShit : GameObject; private var zoom = false; private var defaultCol : Color; private var spriteRender : SpriteRenderer; function Awake () { spriteRender = gameObject.GetComponent.<SpriteRenderer>(); defaultCol = spriteRender.color; } function FixedUpdate () { if(zoom){ ZoomAnim(); } OnTouch(); } function OnMouseDown () { /* spriteRender.color = selectedCol; yield WaitForSeconds (0.1f); spriteRender.color = defaultCol; zoom = true;*/ } function OnTouch () { if(Input.touchCount > 0) { var touch : Touch = Input.GetTouch(0); if(touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled){ spriteRender.color = selectedCol; yield WaitForSeconds (0.1f); spriteRender.color = defaultCol; zoom = true; } } } function ZoomAnim () { cam.transform.position = Vector3( Mathf.Lerp(cam.transform.position.x, gameObject.transform.position.x, Time.deltaTime * 5.0), Mathf.Lerp(cam.transform.position.y, gameObject.transform.position.y, Time.deltaTime * 5.0), cam.transform.position.z); cam.orthographicSize = Mathf.Lerp(cam.orthographicSize, camZoom, Time.deltaTime * 5.0); loadingShit.SetActive(true); yield WaitForSeconds(1); Loading(); } function Loading () { var async : AsyncOperation = Application.LoadLevelAsync(level); yield async; } Anyone had this issue before that has a solution for my problem? Please? P.S excuse my lousy coding.
You want to register a click only when the user removes the finger, not at the moment the user touches the screen. You also might want to check the duration from the user presses until he releases, and the difference in position.
I thought about that but yeah that would require some timing, trouble is i don't how to put it to code.
You could probably use the Untiy Event System for this. There are also gesture packages on the asset store that will handle it for you.