Skip to content

Instantly share code, notes, and snippets.

@TheCuttlefish
Last active June 16, 2024 09:49
Show Gist options
  • Save TheCuttlefish/008250705a5bcd585f2865d0124a300c to your computer and use it in GitHub Desktop.
Save TheCuttlefish/008250705a5bcd585f2865d0124a300c to your computer and use it in GitHub Desktop.
The Sierpinski triangle ( in C# + camera depth only version)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spawner : MonoBehaviour
{
public List<Transform> points = new List<Transform>(); // add 3 points in the world
public GameObject point;// -- can be used for spawning
public Gradient curve;
// Update is called once per frame
void Update()
{
DrawLine();
}
private void DrawLine()
{
int rnd = Random.Range(0, points.Count);
Vector3 newPos = points[rnd].position;
transform.up = Vector3.Normalize(newPos - transform.position);
transform.Translate(0, Vector3.Distance(transform.position, newPos) * 0.5f, 0, Space.Self);
Debug.DrawLine(transform.position, newPos);
GetComponent<SpriteRenderer>().color = curve.Evaluate(Random.Range(0f, 1f));
//Instantiate(point, transform.position, Quaternion.identity);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment