- Home /
iTween on GuiTexture
I'm trying to animate a guiTexture with iTween, but when I apply the code to it up +1, it don't stop up, and go out of the screen, I'm using the same code on a cube to jump, and it's working fine, it up the selected value and them down.
Take a look on the code:
public void Start()
{
iTween.MoveTo(gameObject, iTween.Hash("y", 1, "easeType", "easeOutQuad", "speed", 1));
}
What's the error ?
Answer by dannyskim · Apr 29, 2013 at 05:24 PM
GUITextures are not your traditional transforms in the sense that they do not use the same local coordinates as in game items. Per the Unity documentation:
Their positioning and scaling is performed along the x and y axes only, and they are measured in Screen Coordinates, rather than World Coordinates.
http://docs.unity3d.com/Documentation/Components/class-GuiTexture.html
So when you think about it, 1 on the Y axis is going to be the top of the viewport screen.
If you're wanting to position them relative to something in terms of World Coordinates, you can use the built in functions provided by the Camera class:
http://docs.unity3d.com/Documentation/ScriptReference/Camera.html
Such as WorldToScreenPoint, or WorldToViewportPoint
Thanks guy, the real thing that I want to do is animate them using iTween, like the example of iTween, founded here:
I understand that, what I'm telling you is, is that your value of 1 for "y" is animating it off screen. Try changing the 1 to 0.75f and see if it stops.
To clarify what i'm saying, change the Y position of the GUITexture and see where it ends up.
Oh, sorry, now I understand, it worked, changed 1 to 0.2, worked perfectly +1 for you