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 /
avatar image
0
Question by Ultrapilpo · Mar 28, 2016 at 12:43 AM · inventory systemdraggingevent-handlingevent handlersdraganddrop

OnDrag, OnPointerEnter, OnMouseOver for gameobjects on a canvas

I have a canvas with 4 'slots' on it. These slots are just gameobjects.

I'm looking to be able to drag these slots. So I have one script attached to the canvas with the 4 slots created in that script and given names.

I want to be able to click and hold on one of the slots and have the system know that I have chosen to drag 'Slot 3' for example. At the moment the most accurate I can get is literally just being able to detect that I am dragging the canvas as a whole, but I want to be able to drag the slot gameobjects on this canvas.....

I have tried several ways so far...

 public void OnDrag(PointerEventData data)
 {

     Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     RaycastHit hit;
     if (Physics.Raycast(ray, out hit))
     {
         Debug.Log(hit.collider.name);
     }
 }

Using a combination of OnDrag and raycast it doesn't detect the gameobject slots on the canvas, the only output of the above code is ..."Terrain"...so it just skips the canvas and points at the terrain behind it...No luck here

My second attempt is below....

 public void OnPointerEnter(PointerEventData data)
 {
     print(gameObject.name);
 }

Output: "equipfield"...this is the name of the canvas...

So the most luck I have had is with OnPointerEnter but still can't get it to detect the individual slot gameobjects.

Anyone have any ideas how I can do 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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Parent Event Handler Overriding Child Handler 0 Answers

Following instruction for drag and drop 3d object unity but not working 1 Answer

How to drag Unity Objects to other c# application 0 Answers

Help, Use event system IPointerClickHandler 1 Answer

Fire an event when gameObject has been renamed? 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