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
1
Question by Hakimo · Jan 24, 2011 at 08:18 AM · guiitween

Making iTween work with OnGUI functions

Hi, I've just downloaded iTween and have been playing around with it. At the moment, I'm trying to animate GUI buttons but not sure how to approach it. I've tried using: ... if (GUI.Button (Rect (310,40,280,20), "First Button")) { print("Do somethin"); iTween.ValueTo(myGUI, {"from":(Rect(310,40,280,20)), "to":(Rect(250,20,120,10)), "onUpdate":"myButton"}); }

function myButton(Rect){ print("myButton"); } It didn't have any errors but nothing is happening. Hope someone can help.

Thanks in advance. -Hakimo

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

3 Replies

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

Answer by 3DMagicVR · Jan 27, 2011 at 02:13 PM

Hi Hakimo, I suggest this:

var buttonRect : Rect = Rect(pos.x,pos.y,width,height);

GUI.Button(buttonRect, "Text");

iTween.ValueTo(myGUI, {"from",(Rect(310,40,280,20)), "to",(Rect(250,20,120,10)),"onupdate","myButton","onupdateparams","Rect","time",1,"easetype","spring"});

function myButton(size : Rect){ buttonRect = size; } // Check the syntax use "," rather then ":" for the values

This way you can manipulate the size and position of your GUIButton, you need to use the Rect value from the iTween (from, to), I have the same problem many days a go.

Hopes this help to you, have a great programming day.

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 Hakimo · Jan 31, 2011 at 04:34 AM 0
Share

Thanks very much 3D$$anonymous$$agicVr! It works fine now, although I'm not sure if it's a version thing but I had to make some changes. I still have to use the ':' symbol for the hashtables and I changed the the "Rect" in Valueto to "Size". Thanks again :)

avatar image ben · Mar 18, 2011 at 11:40 AM 0
Share

whats myGUI where u have declared and defined it

avatar image PuneetK · Sep 19, 2013 at 12:37 PM 0
Share

What is myGui?

avatar image
1

Answer by Robindoo · Jan 24, 2011 at 08:38 AM

You can try

if(GUI.Button(Rect(x,y,280,20), "First Button"))
{
     iTween.MoveTo(myGUI, {"x": 250, "y":20,});
} 

By setting the GUI.Button x and y value to a variable, you can then move the GUI Button with the script. Hopefully this is what you wanted.

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 Hakimo · Jan 25, 2011 at 03:32 AM 0
Share

Thanks Robindoo. I tried using the code you gave me but it only affects the x and y values for the gameObject rather than the values in the script itself.

avatar image Robindoo · Jan 25, 2011 at 04:17 AM 0
Share

Haha. I just tried out iTweens not too long ago as well. $$anonymous$$anaged to do just some simple move with the script. Funny thing is anything in the hashtable doesnt show any errors even if you type anything wrong. You can check this link out on how to use most of the other functions.

http://pixelplacement.com/itweenARCHIVE/

avatar image Hakimo · Jan 26, 2011 at 09:23 AM 0
Share

Thanks. There's no errors but I guess the problem with my code is that it's not accessing the components I want. It keeps changing the values of the transform values rather than in the script. Thanks again. I'll try and figure it out.

avatar image
1

Answer by dentedpixel · Feb 12, 2013 at 02:37 PM

If you are looking to animate GUI elements I would recommend using the tweening engine LeanTween instead. It makes this task very easy. Here is an example of how you can tween a button with very little code:

 // Javascript Code
 private var bRect:LTRect = new LTRect( 0, 0, 100, 50 );
 function OnGUI(){
  if(GUI.Button(bRect.rect, “Scale”)){
   LeanTween.scale( bRect, Vector2(bRect.rect.width, bRect.rect.height) * 1.3, 0.25 );
  }
 }
 // C# Code
 private LTRect bRect = new LTRect( 0f, 0f, 100f, 50f );
 void OnGUI(){
  if(GUI.Button(bRect.rect, “Scale”)){
   LeanTween.scale( bRect, new Vector2(bRect.rect.width, bRect.rect.height) * 1.3f, 0.25f );
  }
 }

You can find more detailed examples of how to tween GUI Elements here: http://dentedpixel.com/developer-diary/animate-unity-gui-elements-with-ease/

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

2 People are following this question.

avatar image avatar image

Related Questions

GUI GameObject Button? 1 Answer

iTween.FadeTo - Prevent Going to 100% Alpha? 0 Answers

iTween multiple GUI elements with one callback 1 Answer

iTween and texture problem 0 Answers

New Gui and iTween 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