Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Frostbite23 · May 25, 2015 at 09:45 PM · androidjavascriptmobileclicktap

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;
 }
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Frostbite23 · May 25, 2015 at 10:11 PM 0
Share

I should note that I did in fact try out tapCount but that didn't work out to well.

avatar image Frostbite23 · May 26, 2015 at 12:23 AM 0
Share

Help anyone?

avatar image Frostbite23 · May 26, 2015 at 10:59 PM 0
Share

Anyone else please?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Frostbite23 · May 26, 2015 at 03:51 AM 0
Share

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.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to detect swipe on an Android device using javascript? 0 Answers

Calling an Android plugin from Javascript? 0 Answers

GUI.DrawTexture wrong on mobile build 0 Answers

OnMouseDown alternative for Mobile 5 Answers

How do i need to change this script for mobile? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges