• 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 /
This question was closed Oct 30, 2014 at 10:03 AM by Mayank Ghanshala for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Mayank Ghanshala · Oct 29, 2014 at 09:03 AM · onmouseup

OnMouseUp not working

I have made a button prefab which has a boxcollider2d with it and a script which contain OnMouseUp method . It is working in menu and OnMouseUp is being called but in game scene it is not being called. I have no idea how same prefab can work in one scene and not in another.

Comment
Add comment · Show 10
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 MrSoad · Oct 29, 2014 at 09:27 AM 1
Share

Is there any variation in the distance between the camera and the button in the scene that works compared to the scene that does not?

avatar image tanoshimi · Oct 29, 2014 at 10:57 AM 1
Share

Is there anything (even potentially invisible) between the camera and the button?

avatar image MrSoad · Oct 29, 2014 at 11:36 AM 1
Share

So the button is always exactly the same distance from the camera? If so then do what tanoshimi says and let us know how you get on.

avatar image robertbu · Oct 29, 2014 at 03:36 PM 2
Share

Put this script on an object somewhere in the scene:

 #pragma strict
 
 function Update() {
      var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
      var hit : RaycastHit;
      if (Physics.Raycast(ray, hit) {
           Debug.Log("Hitting: "+hit.name+", "+hit.tag);
      }
 }

This will tell you what object (if any) the ray is hitting. Also take a look at your object in the Scene view to make sure the collider is sized and positioned correctly.

avatar image MrSoad · Oct 29, 2014 at 04:25 PM 1
Share

I was thinking of writing a script like that for him, but I had other commitments today... A thumbs up for you robertbu :)

Show more comments

2 Replies

  • Sort: 
avatar image
1

Answer by Aladine · Oct 29, 2014 at 04:57 PM

OnMouseUp/Down/Over/Drag require a collider or a GUIElement, does your object have that ?

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 Mayank Ghanshala · Oct 30, 2014 at 10:04 AM 0
Share

ya I have and it resolved. It was z axis distance. Thx for your time.

avatar image
0
Wiki

Answer by AlanMattano · Oct 29, 2014 at 04:56 PM

Try in update. First debug on mouse ButtonUp. This c# script name DebugOnMouseUp will hide your mouse arrow when left mouse button is press and debug if the mouse button is up. It will help you to debug your mouse button.

 using UnityEngine;
 using System.Collections;
 
 public class DebugOnMouseUp : MonoBehaviour
 {
 
         void RightMouseWasPressed ()
         {
                 Screen.lockCursor = true;// hide mouse arrow
         }
     
     
         void MyFunction ()
         {
                 Debug.Log ("Left Mouse button up! " + "\n");
         
                 Screen.lockCursor = false;// Show mouse arrow
         }
     
         // Update is called once per frame
         void Update ()
         {
                 if (Input.GetMouseButtonDown (0))
                         RightMouseWasPressed ();// Hide left mouse
         
                 if (Input.GetMouseButtonUp (0))
                         MyFunction ();  // Show left mouse
         }
 }




Comment
Add comment · 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

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

31 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Animate Button/Object When Clicked In Game 2 Answers

OnMouseUp and GUITexture 1 Answer

Problem with OnMouseUp 1 Answer

OnMouseDown 2 Answers

On Mouse Up On Multiple GUI Texts 0 Answers


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