Disclaimer: Please read the entire post before posting; I don’t want people to answer the question as if the ‘title’ of the post was the only thing I wrote.
I’ve been trying to make a main menu GUI box move from one area to another. I want the box to move from the right of the screen to the center of the screen. Here’s some code I found online:
}
`
I tested it, and it works in a rudimentary sense (the box will appear on the left then further to the right when you press the ‘Space’ key), but I’m still unsure as to how I can make the object move at, say, 5 units per second.
I got help from another website to create a rudimentary animation to scroll from left to right when the game first starts. Basically, the value for the box’s position on the x-axis is increased over time at X amount of spaces until it hits a limit set up for its right-hand side. Here’s the code:
`//moves GUI at start of the program
void AnimateGUIAtStart() {
bool atRight = false;
float moveSpeed = 0.0f;
float alphaChangeSpeed = 0.0f;
if (atRight == false)
{
moveSpeed = 5.0f;
alphaChangeSpeed = Time.deltaTime; //fade into view by changing alpha channel to 1.0f
}
if (moveSpeed != 0.0f)
{
boxPosX += moveSpeed;
alphaNum += alphaChangeSpeed;
//sets values of boxPosX, alphaNum to limits if they go above limits
if (atRight == false && boxPosX >= boxLimitRightX)
{
boxPosX = boxLimitRightX;
moveSpeed = 0.0f;
alphaNum = 1.0f;
alphaChangeSpeed = 0.0f;
atRight = true;
//isMovingLeft = true;
}
}
}`
The box can be moved back to the left if you set up the boundaries, moveSpeed, etc. to their respective opposites.
Unfortunately, I’ve found if extremely difficult to use this for when you want to switch over to another menu (e.g. if you want the animation to occur after pressing a button that would take you to another menu).