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 /
  • Help Room /
avatar image
0
Question by ClearRoseOfWar · Jun 01, 2016 at 03:48 PM · uitransformcanvasprogrammingrect

Need Rect Transform Movement Tips

Hey Everyone!

Im trying to make a slot machine using canvas UI.

Not sure what they are called, but the 3 wheels that spin are composed of 2 sprites each. One on the top and one on the bottom. when the bottom sprite is no longer in view (Just below the slot window), it goes on top of the other sprite to simulate a never ending, spinning wheel.

To do this, I simply have an if statement that checks if the sprites transform.position.y is less than -420, and if so, then add 781 to its Y Position.

This was working great until I compiled it to my android (where the screen is smaller) that I found out a problem with this method.

When I change the size of my game window everything goes out of wack.

I think its because -420 is a different location when the screen is made smaller.

Also, I have the canvas set to scale with screen size, not sure if that has something to do with it

Can some smart person explain to me how can I overcome this problem?

EDIT:

At closer inspection, I see that when I change the size of the screen it doesnt detect its Y position on time, because step by step, i am able to see its passing -420

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 Mmmpies · Jun 01, 2016 at 04:23 PM 0
Share

How can you see it passing -420 but Unity not detect it's passed -420! Even if you do this in Unity with a smaller screen size there has to be some other factor making it not work. If the UI scales but your figures don't then surely moving to 781 away would be too far.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ClearRoseOfWar · Jun 01, 2016 at 05:03 PM

I needed to be using localPosition. I was only using position to alter my transform movement...

Comment
Add comment · 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
0

Answer by Mmmpies · Jun 01, 2016 at 03:57 PM

Probably the best way is to calculate that figure from your Screen Width or Height depending on which way the rect moves. I'll assume height as that's normal for a slot machine / fruit machine.

Find the height of the screen and see how much you have to divide the height by to get the correct values then use that division to place the items correctly. You may need to move anchors to the corners of each UI element to scale properly as well.

When the game starts on your phone it'll get that screen height and scale the values by the division rather than a fixed value. You'll need one for the too far away and another for the move to.

Comment
Add comment · 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

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

82 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

Related Questions

Button custom collider 0 Answers

How to make a restart button pop up after character has died? 2 Answers

Rect2D with 3D Object in Canvas,Rect2D & 3D Objects within Canvas 0 Answers

View individual Rect boxes when multiple UI elements are selected? 0 Answers

Prefab always instanciated at 0 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