2025-04-18 15:54:50 -04:00
|
|
|
using UnityEngine;
|
|
|
|
|
using Game;
|
|
|
|
|
using Music;
|
|
|
|
|
using Player;
|
|
|
|
|
|
2025-04-16 19:57:54 -04:00
|
|
|
namespace Game
|
|
|
|
|
{
|
2025-04-18 15:54:50 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// This class handles the infinite scrolling effect for the background.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class InfiniteScroll : MonoBehaviour
|
2025-03-03 11:35:56 -05:00
|
|
|
{
|
2025-04-18 15:54:50 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// The speed at which the background scrolls.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float speed;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The starting position of the background.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float start;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The ending position of the background.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float end;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the position of the background to create a scrolling effect.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void Update()
|
2025-03-03 11:35:56 -05:00
|
|
|
{
|
2025-04-18 15:54:50 -04:00
|
|
|
// If the background moves past the end position, reset it to the start position
|
|
|
|
|
if (transform.position.x > end)
|
|
|
|
|
{
|
|
|
|
|
transform.position = new Vector3(start, transform.position.y, transform.position.z);
|
|
|
|
|
}
|
|
|
|
|
// If the background moves past the start position, reset it to the end position
|
|
|
|
|
else if (transform.position.x < start)
|
|
|
|
|
{
|
|
|
|
|
transform.position = new Vector3(end, transform.position.y, transform.position.z);
|
|
|
|
|
}
|
2025-03-03 11:35:56 -05:00
|
|
|
|
2025-04-18 15:54:50 -04:00
|
|
|
// Move the background to the right based on the speed and time elapsed
|
|
|
|
|
transform.position += speed * Time.deltaTime * Vector3.right;
|
|
|
|
|
}
|
2025-03-03 11:35:56 -05:00
|
|
|
}
|
|
|
|
|
}
|