forked from RonenNess/UnityUtils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextureFan.cs
60 lines (47 loc) · 1.46 KB
/
TextureFan.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* Implements a texture quad fan from a single quad, useful to represent semi-3d trees in old game graphics.
*
* Author: Ronen Ness.
* Since: 2018.
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace NesScripts.Graphics
{
/// <summary>
/// Turn a textured quad into a textured fan (useful for trees, for example).
/// </summary>
public class TextureFan : MonoBehaviour {
/// <summary>
/// How many sides this textured fan should have.
/// </summary>
public int NumberOfSides = 2;
// Use this for initialization
void Start () {
// first remove self, so we won't create endless fan leafs
Destroy(this);
// get prototype to clone next type
GameObject toClone = gameObject;
// now clone based on number of leafs
for (int i = 0; i < NumberOfSides * 2; ++i) {
// clone self
var newSide = Object.Instantiate(toClone);
Destroy (newSide.GetComponent<TextureFan> ());
// rotate it
newSide.transform.parent = transform;
newSide.transform.localRotation = Quaternion.identity;
newSide.transform.Rotate(new Vector3(0, 1, 0), (180 / NumberOfSides) * i);
newSide.transform.localScale = Vector3.one;
newSide.transform.localPosition = Vector3.zero;
// set this side as the next object to clone
toClone = newSide;
}
// remove original mesh renderer
Destroy(GetComponent<MeshRenderer>());
}
// Update is called once per frame
void Update () {
}
}
}