- Home /
Mobile Tap Issue
Hi guys, Im making a navigation app and currently right now its for mobile as you can tell. However I have 4 sprites in my scenes that have colliders. When I slide or move over one of these sprites (by moving my finger across the screen) and my finger hits it on accident or on purpose, the script in those sprites uses a onMouseDown and thinks its a click and then it automatically loads into the next scene. How can I fix this?
When I move over these sprites which take of the mass majority of the scene and when my finger is right on it and I want to move my finger left or right or up or down, it triggers the clicking function automaticlly and then loads into the next scene.
Heres my code
Mobile Movement #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;
function Awake () {
foto = GetComponent(Camera);
}
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;
fingerPos = touch.position;
zoom = 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;
}
else if(touch.phase == TouchPhase.Stationary){
lastPos = fingerPos;
fingerPos = touch.position;
xPos = 0;
yPos = 0;
zoom = true;
}
else if(touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled){
xPos = 0;
yPos = 0;
zoom = true;
}
}
transform.position += Vector3(-xPos * sensitivity, -yPos * sensitivity, 0.0f);
transform.position = Vector3(Mathf.Clamp(transform.position.x, maximumX, minumumX), Mathf.Clamp(transform.position.y, maximumY, minumumY), transform.position.z);//clamp x
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);
}
}
and heres the script that are on my sprites #pragma strict
var cam : Camera;
var selectedCol : Color;
var camZoom : float = 0.0f;
var level : String;
private var loadingShit : GameObject;
private var zoom = false;
private var defaultCol : Color;
private var spriteRender : SpriteRenderer;
function Awake () {
spriteRender = gameObject.GetComponent.<SpriteRenderer>();
defaultCol = spriteRender.color;
loadingShit = GameObject.FindGameObjectWithTag("Loading");
}
function FixedUpdate () {
if(zoom){
ZoomAnim();
}
}
function OnMouseDown () {
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;
}
I should note that I did in fact try out tapCount but that didn't work out to well.
Answer by Austin_G · May 26, 2015 at 03:47 AM
Use OnMouseButtonUp instead. It might not be a permanent solution, but it will definitely be less irritating for now.
Thanks but I'm not looking for a temporary solution, I need a permanent one and one that can work well with my current situation.