How do I make text move up?
I am making a credit reel in my game. When the CREDIT button is clicked, I want the names to slide up the screen. I do not want to animate it, because I have yet to touch the Unity Animation Software and do not want to start, unless it is the only way. Is there anyway to call the CREDIT text and make it move up a certain number of pixels after every second in a float or such?
Answer by Sgt_Spike · Dec 02, 2019 at 11:31 PM
Yes this is indeed possible. Here's the code I used for my old game. You may need to improve some parts but it should work.
public Scrollbar creditRoll;
private bool isRolling;
private bool startCredits;
private void Start()
{
startCredits = false;
isRolling = true;
creditRoll.value = 1f;
InvokeRepeating("RollCredits", 0f, 0.0002f);
}
public void CallCredits()
{
startCredits = true;
}
private void RollCredits()
{
if (startCredits == true)
{
if (isRolling == true)
{
if (creditRoll.value > 0.02f)
{
creditRoll.value = creditRoll.value - 0.00005f;
}
if (creditRoll.value == 0.02f || creditRoll.value < 0.02f)
{
StartCoroutine("FinishCredits");
isRolling = false;
}
}
else
{
return;
}
} else
{
return;
}
}
IEnumerator FinishCredits()
{
yield return new WaitForSeconds(6f);
// add code for finishing credits (return main menu, etc.)
}
The 0.00005f inside the code determines how fast it will run. You can change this to a pre-defined float if you wish for more efficiency.
If you need help setting up the UI, here's the layout I used:
UICanvas is a canvas
Credits is a panel (Used for background)
Scrollrect is an empty gameobject (With components mask and scrollrect)
Content is an empty gameobject (Used to contain your data, you can add components to organise it)
Scrollbar is a vertical scrollbar (May want to make it transparent)
For your scrollrect component, set the content object to (content object), and the vertical scrollbar to your scrollbar.
Hopefully that all works for you. You may want to look into Unity animation soon though. It's not really as hard as it looks and animations are great :D Good Luck!