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 patrick750 · Apr 01, 2020 at 06:17 AM · dragging

How can i activate the OnDrag event without dragging my mouse?

I'm implementing an Action Bar system where the user can drag any ability into any other slot. If the user moves the ability to an empty slot, I have that working fine. If the user moves the ability to an occupied slot, right now I have the choice of making it take over the data from the occupied slot or swapping the data. Neither of these solutions seem good enough for me.

I would like for the occupied slot to be picked back up so that I can move it to a new slot. This seems like the most user-friendly solution (and lots of MMOs do this, e.g. WoW).

I'm currently using OnBeginDrag, OnDrag and OnEndDrag functionality to do what I need. Ideally I'd like the occupied ability to be the 'eventData' of 'OnDrag' when i let go of my left mouse button but I can't find a way to do this (aka call the Event while not actually having mouse button held).

Here is what I am doing as it relates to the question. The first line is the only code that is in OnDrag and the other lines are the basics of what I am doing in OnEndDrag.

         rectTransform.transform.position = Input.mousePosition;


         string tempAbilityName = newAbilitySlot.GetComponent<RunAbilityAndCooldowns>().abilityName; 

         newAbilitySlot.GetComponent<RunAbilityAndCooldowns>().abilityName = 
         currentlyDraggedAbility.GetComponent<RunAbilityAndCooldowns>().abilityName;

         currentlyDraggedAbility.GetComponent<RunAbilityAndCooldowns>().abilityName = tempAbilityName;

This stores the ability in the occupied slot temporarily, sets the new ability to the old, and the old to the temporary (aka new). I'm doing this for many variables which are stored in each instance of the script on each action bar slot. This allows me to swap abilities easily, but ideally I'd like to be able to pick up the 'newAbilitySlot' instead of just placing it where currentlyDraggedAbility was.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Casiell · Apr 01, 2020 at 09:17 AM

The idea is to separate your moving methods from OnXDrag events. Drag events should only parse the eventData and call movement methods with parsed parameters. This way you will be able to mock those parameters yourself and achieve what you want.

If you want more specific help, then you need to provide some code.

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 patrick750 · Apr 01, 2020 at 11:55 AM 0
Share

Sorry, not entirely sure what you mean by this. I added some of the code that I'm using to make the switches during OnDrag and OnEndDrag.

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

126 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

Related Questions

How to move an object X or Y axis only 1 Answer

Rotation of gameobject while dragging on the screen not working as expected in unity 4.6 0 Answers

restrict scaling 2 Answers

Adding Accelerating to a Wheel of fortune 0 Answers

"Image.raycastTarget = false" not consistent between PC and Android 1 Answer


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