Fractal
This commit is contained in:
45
Assets/Script/Fractal.cs
Normal file
45
Assets/Script/Fractal.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Fractal : MonoBehaviour
|
||||
{
|
||||
[SerializeField, Range(1, 8)]
|
||||
int depth = 4;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
name = "Fractal " + depth;
|
||||
Debug.Log(name);
|
||||
|
||||
if (depth <= 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var childA = CreateChild(Vector3.up, Quaternion.identity);
|
||||
var childB = CreateChild(Vector3.right, Quaternion.Euler(0f, 0f, -90f));
|
||||
var childC = CreateChild(Vector3.left, Quaternion.Euler(0f, 0f, 90f));
|
||||
var childD = CreateChild(Vector3.forward, Quaternion.Euler(90f, 0f, 0f));
|
||||
var childE = CreateChild(Vector3.back, Quaternion.Euler(-90f, 0f, 0f));
|
||||
|
||||
childA.transform.SetParent(transform, false);
|
||||
childB.transform.SetParent(transform, false);
|
||||
childC.transform.SetParent(transform, false);
|
||||
childD.transform.SetParent(transform, false);
|
||||
childE.transform.SetParent(transform, false);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
transform.Rotate(0f, 22.5f * Time.deltaTime, 0f);
|
||||
}
|
||||
|
||||
private Fractal CreateChild(Vector3 direction, Quaternion rotation)
|
||||
{
|
||||
var child = Instantiate(this);
|
||||
child.depth = depth - 1;
|
||||
child.transform.localPosition = 0.75f * direction;
|
||||
child.transform.localRotation = rotation;
|
||||
child.transform.localScale = 0.5f * Vector3.one;
|
||||
return child;
|
||||
}
|
||||
}
|
11
Assets/Script/Fractal.cs.meta
Normal file
11
Assets/Script/Fractal.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bef3764eec961e04db4297ce68f82391
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user