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
2
Question by sdhdsfghdfghd · Jun 17, 2015 at 07:02 PM · uitextitweenpanel

Using iTween with the new Unity UI

I'm creating a simple slide-in animation for my game. It is a GUI box shown at the bottom with character dialog inside.

The animation looks as follows:

A square slides in from the left, then waits a bit, then expands to its full width.

The box is made using Unity's GUI Box. I'm trying to update it to use Unity 5's new UI system using a Panel and Text, but animating the width and position is proving to be harder than I thought.

 void Start() {
 
         iTween.ValueTo(gameObject, iTween.Hash(
                 "from", initialX,
                 "to", finalX,
                 "time", slideInTime,
                 "onUpdate", "slideIn",
                 "easeType", easeType
             )
          );
 
         iTween.ValueTo(gameObject, iTween.Hash(
             "from", initialBoxWidth,
             "to", finalBoxWidth,
             "delay", waitTime,
             "time", expandTime,
             "onUpdate", "expand",
             "easeType", easeType
             )
         );
     }
 
     void OnGUI() {        
         GUI.Box (new Rect(x, y, boxWidth, boxHeight), boxString);
     }
 
     void slideIn(float newPosition) {
         x = newPosition;
     }
 
     void expand(float newWidth) {
         boxWidth = newWidth;
     }

Is it possible to achieve the same effect with Panels and Text?

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

2 Replies

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

Answer by sdnj · Jul 27, 2015 at 02:43 PM

Hello sdhdsfghdfghd,

yes, it is possile to achieve the same effect with Unity's new UI. Just keep in mind, that you are now working with the RectTransform as a base. You can (buy and) download examples on how to animate uGUI elements from the developer's homepage. I also wanted to create a slide-in animation just like you and figured it out myself:

 public RectTransform uGuiElement;
 public Vector2 targetPosition;

 public void SlideIn(){
     iTween.ValueTo(uGuiElement.gameObject, iTween.Hash(
         "from", uGuiElement.anchoredPosition,
         "to", targetPosition,
         "time", animationTime,
         "onupdatetarget", this.gameObject, 
         "onupdate", "MoveGuiElement"));
     }
 }
 
 public void MoveGuiElement(Vector2 position){
     uGuiElement.anchoredPosition = position;
 }

Hope this is what you were looking for!

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 zbalai · May 03, 2016 at 04:12 PM -1
Share

I believe $$anonymous$$oveGuiElement should have Vector3, like this

public void $$anonymous$$oveGuiElement(Vector3 position){

avatar image sdnj zbalai · May 04, 2016 at 07:31 AM 0
Share

Nope, the variable anchoredPosition is of the type Vector2.

avatar image mmcelt · Mar 24, 2018 at 06:40 PM 0
Share

None of those examples deal with the new UI.

avatar image Keith-Fox mmcelt · Apr 11, 2018 at 02:54 AM 0
Share

The new UI uses RectTransform for it's coordinate system - including distances from each side. iTween only has native commands for the standard unity Vector3, as for as movement is concerned. Therefore, you have to use iTween's ability to modify a value directly and callback the new value over time.

I just wish there was a way to do this to an array of items.

avatar image
0

Answer by Fiaz_Ali · Jun 16, 2020 at 03:48 PM

Anyone still having issue moving UI with ITween then simply use the "isLocal" property and set it to true. Now record the positions from the canvas where you want your UI to move and pass those values below line of code.

 iTween.MoveTo(button_gameObject, iTween.Hash("position", new Vector3(x_pos, y_pos, 0), "speed", 500f, "easetype", "easeInQuad", "islocal", true));

x_pos : The position of UI image where it is going to transfer/animate in the Canvas.

y_pos : The position of UI image where it is going to transfer/animate in the Canvas.

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

7 People are following this question.

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

Related Questions

UI: Creating UI based on many strings 0 Answers

Canvas UI Priority layers 1 Answer

Make UI always center the panel 1 Answer

How to make UI Panel scale to fit content 2 Answers

Button on Panel is not responding 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