Added comments to everything
This commit is contained in:
@@ -1,24 +1,48 @@
|
||||
using UnityEngine; using Game; using Music; using Player;
|
||||
using UnityEngine;
|
||||
using Game;
|
||||
using Music;
|
||||
using Player;
|
||||
|
||||
namespace Game
|
||||
{
|
||||
public class InfiniteScroll : MonoBehaviour
|
||||
{
|
||||
public float speed;
|
||||
public float start;
|
||||
public float end;
|
||||
|
||||
private void Update() // Moves the background
|
||||
/// <summary>
|
||||
/// This class handles the infinite scrolling effect for the background.
|
||||
/// </summary>
|
||||
public class InfiniteScroll : MonoBehaviour
|
||||
{
|
||||
if (transform.position.x > end)
|
||||
{
|
||||
transform.position = new Vector3(start, transform.position.y, transform.position.z);
|
||||
}
|
||||
else if (transform.position.x < start)
|
||||
{
|
||||
transform.position = new Vector3(end, transform.position.y, transform.position.z);
|
||||
}
|
||||
/// <summary>
|
||||
/// The speed at which the background scrolls.
|
||||
/// </summary>
|
||||
public float speed;
|
||||
|
||||
transform.position += speed * Time.deltaTime * Vector3.right;
|
||||
/// <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()
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
// Move the background to the right based on the speed and time elapsed
|
||||
transform.position += speed * Time.deltaTime * Vector3.right;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user