Can someone help me with the formula/algorithm to create an expanding GUITexture.
At 100% (meaning fully expanded) the texture will be at coordinates, x = 0, y = 0;
When its retracted should it be invisible, scaled down, or instantiated? In any case, the player clicks a “button” and then from location x and y the GUITexture expands over a couple seconds until its at 0,0 at 100%
Any suggestions?
Do you mean something like this video (except, of course, I know you mean full-screen)? http://www.youtube.com/watch?v=UdXzraaNvtQ
I don’t use GuiTexture, so I’m not entirely sure how to address your specific issue, but the idea is to interpolate the alpha as well as the rectangle bounds over a given time.
Here’s an abstract example:
float startAlpha = 0;
float endAlpha = 1;
float accumulatedTime = 0;
float fadeSpeed = 1;
void OnGUI()
{
accumulatedTime += Time.deltaTime * fadeSpeed;
if( accumulatedTime > fadeSpeed )
accumulatedTime = fadeSpeed;
float currentAlpha = Mathf.Lerp( startAlpha, endAlpha, accumulatedTime );
// Do something with that alpha
if( accumulatedTime >= fadeSpeed )
{
// We know the fade is done
}
}
That code should smoothly progress the alpha variable between the start value and end value over fadeSpeed seconds.
You can extrapolate that to work with rectangles by doing the same kind of interpolation with each component of the rectangle (startX → endX, startY → endY, startWidth → endWidth, startHeight → endHeight), etc.
.
Why type of math is this that you are using? I’m trying to get better at solving these type of problems. Do you know any good resources to study so that I can figure this kind of stuff on my own?
It’s standard interpolation, or ‘tweening’. There’s a nice library for doing much of this stuff at http://itween.pixelplacement.com/, and a forum thread here at http://forum.unity3d.com/viewtopic.php?t=47351. The design is a bit hard to follow at times, and it’s unnecessarily complex, but it can do some pretty wonderful stuff ‘out of the box’.
For more information, just search these forums for ‘Tween’ and I’m sure lots of information can be found.
.