-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecursiveScaleChange.cs
More file actions
56 lines (53 loc) · 1.33 KB
/
RecursiveScaleChange.cs
File metadata and controls
56 lines (53 loc) · 1.33 KB
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
using UnityEngine;
using System.Collections;
public class RecursiveScaleChange : MonoBehaviour
{
/*this class will start with a gameobject
that has multiple children with possibly multiple grandchildren
on start it will detect any material on any renderer
and change it to a user defined material*/
public float minScale;
public float maxScale;
public float newScale;
public bool randomScale;
public int maxIterations;
public int iterationCount;
// Use this for initialization
void Start ()
{
}
public void Go ()
{
RecursiveReplace (transform, randomScale);
}
private void RecursiveReplace (Transform t, bool r)
{
ScanChildren (t, r, iterationCount);
}
private void ScanChildren (Transform t, bool r, int ilvl)
{
if (iterationCount < maxIterations) {
if (t.childCount != 0) {
int c = t.childCount;
for (int i = 0; i < c; i++) {
iterationCount++;
ChangeScale (t.GetChild (i), r);
ScanChildren (t.GetChild (i), r, iterationCount);
}
iterationCount--;
} else {
iterationCount--;
}
} else {
iterationCount--;
}
}
private void ChangeScale (Transform t, bool r)
{
float s = newScale;
if (r) {
s = Random.Range (minScale, maxScale);
}
t.localScale = t.localScale * s;
}
}