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 /
This question was closed Jun 23, 2016 at 10:57 AM by lightingft for the following reason:

Other: Solved it. I had to use EventSystem, block raycasts on the icons, and use OnBeginDrag, OnDrag and OnEndDrag. OnEndDrag I used eventData.pointerEnter to get the gameObject slot.

avatar image
0
Question by lightingft · Jun 22, 2016 at 05:59 AM · uimousepointer

Get object at mouse position? (UI)

Hey guys, so I'm further working on an inventory system in my game and I've ran into a problem. Basically, what I want to do is when you are dragging an item and stop dragging it at a certain slot (an UI element), it detects which slot is at the current mouse position and performs a function to put the item there.

My current script is rather simple so far:

     public void OnBeginDrag()
     {
         ipos = this.transform.transform.Find("Icon").position;
         dragging = true;
         currentTooltip = "";
         sibling = this.transform.GetSiblingIndex ();
         this.transform.SetAsLastSibling ();
     }
 
     public void OnDrag()
     {
         tooltip = "";
         transform.transform.Find("Icon").position = Input.mousePosition;
     }
 
     public void OnEndDrag()
     {
         this.transform.transform.Find("Icon").position = ipos;
         ipos = Vector2.zero;
         dragging = false;
         this.transform.SetSiblingIndex (sibling);
     }

This is currently the script for the icon to snap back in place (as it doesn't hit a slot). How do I implement it to detect the slot the mouse points at? Thanks in advance.

Edit: Sorry, I mean detecting if the Icon transform is in the slot's bounds.

Comment
Add comment · Show 1
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 KuR5 · Jun 23, 2016 at 10:56 AM 0
Share

Take a look at this Video having demo.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Pointer Enter/Exit keeps triggering on UI element (Image) 3 Answers

How do i disable my buttons while dragging ScrollRect? 0 Answers

PauseMenu - Camera moves in pausemenu 0 Answers

How do i get the child of an GameObject the pointer is hovering over? 0 Answers

Get mesh name with mouse click, then change color (and other properties) of mesh 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