Skip to content

Instantly share code, notes, and snippets.

@fidelsoto
fidelsoto / Extensions.cs
Last active June 5, 2019 21:59
Class contains an extension method for the transform class that adds a Clear function to clear a transform's children. In this code we can see the usage of extension methods and comments.
/// <summary>
/// Extension method for the Transform class, Destroys all of its children starting at a given index (optional, default 0).
/// </summary>
/// <param name="container">The transform containing the child objects.</param>
/// <param name="startIndex">The index at which we should begin destroying the objects.</param>
public static void Clear(this Transform container, int startIndex = 0)
{
for (int i = startIndex; i < container.childCount; i++)
{
Destroy(container.GetChild(i).gameObject); //Use ObjectPool.Destroy to use with pooling system.
@fidelsoto
fidelsoto / Fraction.cs
Last active October 17, 2024 05:35
Fraction Class C#. Supports formatting, comparing and simplifying fractions. In this code we can see the usage of constructors, operator overriding and helper functions.
public class Fraction
{
public int numerator;
public int denominator;
public Fraction(int numerator, int denominator)
{
this.numerator = numerator;
this.denominator = denominator;
}