Created
November 12, 2018 03:37
-
-
Save dave-santiano/211468114f4eee0e2188be54c21017fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class SimpleRecursion : MonoBehaviour { | |
void Start () { | |
//Terminating condition | |
if(transform.localScale.x > 1.001f) | |
{ | |
//Instantiates new cube, then moves it! | |
GameObject newCube = Instantiate(gameObject) as GameObject; | |
newCube.transform.localScale = transform.localScale / 1.01f; | |
newCube.transform.position = new Vector3(transform.position.x, | |
transform.position.y + GetComponent<Renderer>().bounds.size.y, | |
transform.position.z); | |
//Rotation stuff | |
float newX = transform.localEulerAngles.x + 18; | |
float newY = transform.localEulerAngles.y + 15; | |
newCube.transform.Rotate(newX, newY, transform.localEulerAngles.z); | |
//Color Stuff | |
newCube.GetComponent<Renderer>().material.color = new Color(GetComponent<Renderer>().material.color.r + 0.01f, | |
GetComponent<Renderer>().material.color.g, | |
GetComponent<Renderer>().material.color.b); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment