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 danielos1996 · Aug 12, 2020 at 03:11 PM · uigameobjectui imagedrag-and-drop

Detect if UI element is over Gameobject

I want to be able to detect if a UI element is over a gameobject and return true if it is. I need it so that if any part of the UI element is touching the gameobject then it returns true.

I was originally using cursor position but that did not work as something the user can drag and drop the item to the gameobject position and it does not register.

alt text

This should return as true.

alt text

This should return as false.

1.png (140.3 kB)
3.png (78.5 kB)
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 danielos1996 · Aug 28, 2020 at 11:20 AM 0
Share

I cannot fathom how this isn's a more discussed issue. It is literally drag and drop functionality.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Stactic_Games · Aug 12, 2020 at 07:40 PM

use on trigger enter

 OnTriggerEnter()
 {
          //event here
 }

plz help on my question

Comment
Add comment · Show 4 · 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 Spip5 · Aug 13, 2020 at 01:34 AM 0
Share

If you are using 2D, you actually need to use OnTriggerEnter2D.

  • Create a gameobject.

  • Add a CircleCollider2D to that gameobject

  • Add a script to make it follow your mouse

  • On that script add OnTriggerEnter2D and use the documentation to get the behaviour you want

avatar image danielos1996 · Aug 13, 2020 at 07:29 AM 0
Share

On trigger enter does not get activated by UI items over gameobjects.

avatar image Spip5 danielos1996 · Aug 13, 2020 at 10:43 AM 0
Share

Why do you need to use UI items ? A 2D Sprite would be much easier to handle. Add a scipt to make it follow your mouse. UI is, by definition, not made to interract physically with gameobjects :)...

 using UnityEngine;
 using System.Collections;
  
 public class $$anonymous$$ouse$$anonymous$$ove2D : $$anonymous$$onoBehaviour {
  
     private Vector3 mousePosition;
    
     // Update is called once per frame
     void Update () {
         if (Input.Get$$anonymous$$ouseButton(1)) {
             mousePosition = Input.mousePosition;
             mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
             transform.position = mousePosition;
         }
     }
    void OnTriggerEnter2D (Collider2D  col)
     {
             if(col.transform.tag == "mytag")
             {
                      // DO YOUR STUFF 
             }
     }
 }
avatar image danielos1996 Spip5 · Aug 14, 2020 at 08:40 AM 0
Share

It needs to be UI the way I have it. I have a tab that contains multiple tools represented as UI icons like in the image above. The user then drags and drops these icons onto where said tool should be used in the scene.

Using 2D srpites would mean I would loose all the canvas scaling for different devices that I have working. Along with me needing to rewite a lot of work to implament it.

avatar image
0

Answer by danielos1996 · Aug 14, 2020 at 10:03 AM

I'm finding it hard to even get the world position of a moving UI object. I think if I could get that I could atleast make progress.

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 Llama_w_2Ls · Aug 28, 2020 at 11:23 AM 0
Share

Well isnt that just the rect transform?

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

276 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 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 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 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 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 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 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 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 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

How to move UI image between panels 0 Answers

Callback for when a Graphic (Ui) Component is Added to any GameObject using the Editor 0 Answers

Collision between UI element and GameObject 1 Answer

one button to hide and unihed gameobjects 0 Answers

Pixel Perfection unity UI 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