Im using iphone unity and I was wondering if there was anyway to animate GUI, for instance, when the player gets some points, they bounce up and down…
I’m not an iPhone user YET, but I don’t see why not.
You display the points in a specific position on the screen. Just write a function that changes those parameters…
Specifically for bounce you can check out http://www.unifycommunity.com/wiki/index.php?title=Mathfx.
Just further to what cyb3rmaniak said, here’s an example from one of my old scripts (I’ve just cut the relevant part, so there are probably loads of undeclared variables in this snippet):
GUI.Label ( Rect( 0 + offset, 0, Screen.width - offset, Screen.height), "", backgroundStyle);
if (menuMode == 1)
{
offset = Mathf.Lerp(offset, 0, Time.deltaTime * 5);
if (offset <= (Screen.width * 0.05))
{
if (GUI.Button( Rect( (Screen.width * 0.2)-70, Screen.height * 0.8, 140, 50), "Menu 2"))
{
menuMode = 2;
}
}
}
if (menuMode == 2)
{
offset = Mathf.Lerp(offset, Screen.width * 0.56, Time.deltaTime * 5);
if (offset >= (Screen.width * 0.5))
{
if (GUI.Button( Rect( (Screen.width * 0.28)-70, Screen.height * 0.8, 140, 50), "Menu 1"))
{
menuMode = 1;
}
}
}
The above basically creates a label as a background image covering the screen behind the first menu and compresses it over to the right half of the screen when you switch to the second menu. It also hides the controls while the transition is happening.
I had been using it in a start menu to reveal a view of the rendered character for a character customisation screen.
Ok so ive iported the MathsFX file from:
http://www.unifycommunity.com/wiki/index.php?title=Mathfx
How can I get some of my GUIText to bounce?
When I say bounce, I want it to bounce forward towards the user as if it is popping out of the screen… any ideas?
I would use GUIUtility.ScaleAroundPivot. Sth like:
Matrix4x4 old = GUI.matrix; // grab one for backup
// Scale with the scaleFac
GUIUtility.ScaleAroundPivot (Vector2 (scalefac, scalefac), Vector2 (60,20));
// Draw the actual box
GUI.Box (Rect (10,10,100,20), "Bouncing Box");
// Restore the old matrix
GUI.matrx = old;
Then you just need to modify the scaleFac somehow
So, Ive manged to make it grow, but it seems clunky and slow, is there a better way to do this:
var scale = 1;
function OnGUI () {
GUIUtility.ScaleAroundPivot (Vector2 (scale, scale), Vector2 (60,20));
// Draw the actual box
GUI.Box (Rect (10,10,100,20), "Bouncing Box");
}
function Update(){
scale = scale+1;
}
That is how I would do it.
But isn’t it growing rather fast? I would use relative values instead e.g.
scale = scale * 1.01f;
when I add:
scale = scale * 1.01f;
Unity claims that it requires a ; at the end, but there is one, ive typed it out rather than copy and pasting it aswell
The f is only used in C# to identify the value as a float rather than a double. In UnityScript just remove the f.
-Jeremy