Added comments to everything

This commit is contained in:
djkellerman
2025-04-18 15:54:50 -04:00
parent a0305ea0e9
commit 213bb2d14b
39 changed files with 3166 additions and 1796 deletions

View File

@@ -1,33 +1,67 @@
using UnityEngine; using Game; using Music; using Player;
using UnityEngine;
using Game;
using Music;
using Player;
namespace Game
{
public class MovingPlatform : MonoBehaviour
{
public Transform platform;
public int startPoint;
public Transform[] points;
public float speed;
private int i;
void Start() // Sets the initial position of the platform
/// <summary>
/// This class controls a platform that moves between specified points in a loop.
/// </summary>
public class MovingPlatform : MonoBehaviour
{
transform.position = points[startPoint].position;
}
/// <summary>
/// The platform object that will move.
/// </summary>
public Transform platform;
void FixedUpdate()
{
// If the platform is close to the target point, it starts moving to the next one
if (Vector2.Distance(transform.position, points[i].position) < 0.02f)
/// <summary>
/// The index of the starting point for the platform.
/// </summary>
public int startPoint;
/// <summary>
/// An array of points that the platform will move between.
/// </summary>
public Transform[] points;
/// <summary>
/// The speed at which the platform moves.
/// </summary>
public float speed;
/// <summary>
/// The current target point index.
/// </summary>
private int i;
/// <summary>
/// Sets the initial position of the platform to the starting point.
/// </summary>
private void Start()
{
i++;
if (i == points.Length)
{
i = 0;
}
transform.position = points[startPoint].position;
}
/// <summary>
/// Moves the platform between points in a loop.
/// </summary>
private void FixedUpdate()
{
// If the platform is close to the target point, update to the next point
if (Vector2.Distance(transform.position, points[i].position) < 0.02f)
{
i++;
if (i == points.Length)
{
i = 0; // Loop back to the first point
}
}
// Move the platform towards the current target point
GetComponent<Rigidbody2D>().MovePosition(
Vector2.MoveTowards(transform.position, points[i].position, speed * Time.fixedDeltaTime)
);
}
// Moves the platform towards the next point
// transform.position = Vector2.MoveTowards(transform.position, points[i].position, speed * Time.deltaTime);
GetComponent<Rigidbody2D>().MovePosition(Vector2.MoveTowards(transform.position, points[i].position, speed * Time.fixedDeltaTime));
}
}}
}