45 lines
1.7 KiB
C#
45 lines
1.7 KiB
C#
using UnityEngine;
|
|
|
|
public class ScrollText : MonoBehaviour
|
|
{
|
|
public float startSpeed = 10f; // Initial scroll speed
|
|
public float maxSpeed = 100f; // Maximum scroll speed
|
|
public float acceleration = 10f; // Speed increase over time
|
|
public RectTransform textTransform; // Reference to the Text's RectTransform
|
|
public RectTransform maskPanel; // Reference to the Mask Panel
|
|
public float stopAtYPosition = 3736f; // Y position where scrolling stops
|
|
|
|
private float currentSpeed;
|
|
|
|
void Start()
|
|
{
|
|
// Initialize current speed to start speed
|
|
currentSpeed = startSpeed;
|
|
|
|
// Ensure the text starts below the mask panel
|
|
Vector3 startPosition = textTransform.anchoredPosition;
|
|
startPosition.y = -maskPanel.rect.height;
|
|
textTransform.anchoredPosition = startPosition;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
// Stop scrolling if the position has reached or exceeded the stop position
|
|
if (textTransform.anchoredPosition.y >= stopAtYPosition)
|
|
{
|
|
// Ensure the final position is exactly the stop position
|
|
Vector3 finalPosition = textTransform.anchoredPosition;
|
|
finalPosition.y = stopAtYPosition;
|
|
textTransform.anchoredPosition = finalPosition;
|
|
return; // Exit the Update method to stop further scrolling
|
|
}
|
|
|
|
// Increase the speed gradually until it reaches the max speed
|
|
currentSpeed = Mathf.Min(currentSpeed + acceleration * Time.deltaTime, maxSpeed);
|
|
|
|
// Move the text upward
|
|
Vector3 position = textTransform.anchoredPosition;
|
|
position.y += currentSpeed * Time.deltaTime;
|
|
textTransform.anchoredPosition = position;
|
|
}
|
|
} |