Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by azmundai · Aug 24, 2015 at 08:24 PM · mousecanvasmouseclickevent triggering

Event on mouse up

I have a button on a canvas.

The canvas appears when I select a character (the canvas is a child of the character) using SetActive().

What I want to be able to do is click the character, hold the mouse button down, and when I let go of the mouse button, trigger the button below the mouse.

PointerUp and PointerClick events don't seem to work for this ..

Is there any way I can create something like this?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by azmundai · Aug 27, 2015 at 01:52 AM

So I am not sure I completely understand this solution, but ... it seems to be pretty easy to setup. The new event system appears to handle most of this, there just isn't anything built into the buttons like PointerUp.

What I did was just used a simple

             if(Input.GetMouseButtonUp (0) ) {
                 ControllerMouseUp();
             }

in Update, and then

         private void ControllerMouseUp(){
             PointerEventData ped = new PointerEventData(EventSystem.current);
             ped.position = Input.mousePosition;
             List<RaycastResult> rcr = new List<RaycastResult>();
             EventSystem.current.RaycastAll(ped, rcr);
             if(rcr.Count > 0){
                 foreach(RaycastResult r in rcr){
                     if(r.gameObject.tag == "Button"){
                         // DO STUFF
                     }
                 }
             }
         }

You also have to make sure to add

 using System.Collections.Generic;
 using UnityEngine.EventSystems;

at the top of your class. Anyway, hopefully this will help someone :)

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

Answer by Positive7 · Aug 24, 2015 at 08:47 PM

http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseUp.html

 public void OnMouseUp(){
         Debug.Log("OnMouseUp triggered");
     }

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 azmundai · Aug 25, 2015 at 05:31 AM 0
Share

Thanks, i'll try and make that work.

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

26 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

Related Questions

CATCH MOUSE CLICK EVENT ON OBJECTS 0 Answers

Limited response from mouse input in game view. 2019.3 0 Answers

Ignore mouse click outside of the UI 1 Answer

Mouse Clicks Stop After X# of clicks 0 Answers

Detect mouse inputs when the scene is changing to another scene. 2 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