Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Aug 03, 2016 at 08:43 AM by gdowse for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by gdowse · Jun 15, 2016 at 06:15 AM · positioncanvasscaling

eventdata.position issue when using OnDrag

I had a UI button dragging and dropping fine. I then set Canvas scaler to scale with screen size and it has broken the gameobjects position. It appears the position is being scaled up, because when I go to the very bottom left of the screen the object will appear but as I go up and right it scaled to about x position = 120000 and y position = 66000.

I have logged the actually values for eventData.position and it is the same as before, between 0 and 1000 roughly. I can only assume that something is changing the value after my code fires. I have played around with scaling setting but had no luck in fixing the issue.

This is the code I'm using.

 public void OnDrag(PointerEventData eventData){
         Debug.Log("Dragging");
         this.transform.position = eventData.position;
     }
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

  • Sort: 
avatar image
-1
Best Answer

Answer by gdowse · Aug 03, 2016 at 01:27 PM

Fixed this myself.

Changed 'postion' to 'localPosition' and changed some of the settings on the canvas scale.

Comment
Add comment · Show 3 · 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 schwertfisch · Dec 21, 2017 at 08:54 PM 0
Share

this is exactly my problem, but using: this.transform.localPosition=eventData.position; doesn't correct the problem, the position still gets scaled from about (1,1) to (800,800) when OnDrag.

avatar image FlightOfOne · Feb 15, 2018 at 05:15 PM 0
Share

Here's what worked for me:

 public void OnDrag(PointerEventData eventData)
 {
     transform.position += (Vector3)eventData.delta;
 }
avatar image MindGem FlightOfOne · Aug 30, 2021 at 08:19 AM 0
Share

YES MAN!!! finally a clear, simple, correct solution. So many answers that completely replace all code with a ton of complicated things. This is the way to do it.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity canvas keeps changing dimension and position 0 Answers

2D Gameobject Location and scaling in different screen size(mobile) 0 Answers

How to make cubes between 2 point and stick them together? 0 Answers

Unity 5.3 canvas scaling - Android 2 Answers

Scaling panel by different screen sizes 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