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 jjesh · Aug 24, 2015 at 06:23 AM · uiguimovementtimerpanel

Having trouble moving a UI panel

Hi! I'm trying to code in a UI panel moving down, then up on screen at a certain time. However, the panel never moves. Here's the code I have if you can help, it's in C#:

 void Start () 
     {
         speed = 1.0f;
         Protag = GameObject.Find ("Protag");
         player = Protag.GetComponent ("Player") as Player;
         startPos = transform.position;
         topPos = new Vector3 (Screen.width/2,(transform.localScale.y/2 + Screen.height/2), startPos.z);
         bottomPos = new Vector3 (Screen.width/2, Screen.height * -1, startPos.z);
         screenPos = new Vector3 (Screen.width / 2, Screen.height / 2, startPos.z);
         
     }
     
     // Update is called once per frame
     void Update () 
     {
         float step = speed * Time.deltaTime;
         if (countDown) {
             timer += Time.deltaTime;
         }
         if (timer < 3.4  && timer > 3) 
         {
             print("moving down");
             transform.position = Vector3.MoveTowards(transform.position, bottomPos, step);
         }
         if (timer >= 3.4 && timer < 3.5) 
         {
             print("moving up");
             transform.position = Vector3.MoveTowards(transform.position, screenPos, step/4);
         }

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 jjesh · Aug 24, 2015 at 07:25 AM 0
Share

Thanks for the fix! The panel is moving now. However, where it ends up on screen is still different depending on if i have the game window small or maximized, even though everything is based on the panel and screen size. Is there a way to make sure it's movement always looks the same?

Edit: Never$$anonymous$$d. I'm dumb and didn't take all of your advise. Upping the timer gap fixed it. Not sure how to mark a comment as the correct answer, so if you copy your comment as one I'll mark it!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Umresh · Aug 24, 2015 at 10:47 AM

You speed value is small and the timer gap is also small. Try playing with the values. Movetowards will work as long as that condition is true. Or try this

 if (timer < 3.4  && timer > 3) 
         {
             Debug.Log("moving down");
             transform.position = Vector3.Lerp(transform.position, bottomPos.position, step);
         }
         if (timer >= 3.4 && timer < 3.8) 
         {
             Debug.Log("moving up");
             transform.position = Vector3.Lerp(transform.position, screenPos.position, step/4);
         }
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 Umresh · Aug 24, 2015 at 10:50 AM 0
Share

YOu can place another panel and change its anchor point and position it. and get that panel as the bottom pos or the screenpos.

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

26 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

Related Questions

Panel content size fitter not working 2 Answers

How to create scene with multiple panels? 0 Answers

How to set sorting order of UI elements, when Sorting Group doesn't work? 2 Answers

When I duplicate my UI, navigation stops working 2 Answers

TextUI text changes size if resolution changes 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