Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added script that changes leaf-node color

  • Loading branch information...
commit bc2d93716284832ae432a90a3c18af7dc30da694 1 parent 342b171
@corybarr corybarr authored
View
BIN  Assets/Scenes/Dance/Intro/intro4_addingRobinTree.unity
Binary file not shown
View
25 Assets/Scripts/Dance/TreeScripts/LeafNodeColorChanger.cs
@@ -0,0 +1,25 @@
+using UnityEngine;
+using System.Collections;
+
+public class LeafNodeColorChanger : MonoBehaviour {
+
+ private ProceduralTreeSegment pts;
+ public Color leafColor = Color.green;
+
+ // Use this for initialization
+ void Start () {
+ pts = GetComponent<ProceduralTreeSegment>();
+ if (pts == null) {
+ throw new System.Exception("A ProeceduralTreeSegment script must be attached for this script to work");
+ }
+
+ if (pts.DepthLevel == pts.MaxDepth) {
+ transform.renderer.material.color = leafColor;
+ }
+ }
+
+ // Update is called once per frame
+ void Update () {
+
+ }
+}
View
2  Assets/Scripts/Dance/TreeScripts/LeafNodeColorChanger.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 1
+guid: c0a5e366f8d22e04dbcca977be10d64a
View
18 Assets/Scripts/Dance/TreeScripts/ProceduralTreeSegment.cs
@@ -3,17 +3,17 @@
public class ProceduralTreeSegment : MonoBehaviour
{
- public int maxDepth = 7;
public float minBranchAngle = 3f;
public float maxBranchAngle = 35f;
public float sizeScalar = 1f;
public bool verbose = false;
public bool readyToBranch = false;
+ private int maxDepth = 7;
+ private int depthLevel;
private bool branched = false;
private ProceduralTreeSegment branch1;
private ProceduralTreeSegment branch2;
- private int depthLevel;
public Vector3 branchLoc; //DEVEL: delete this. it should only be in the scope of the Branch() method
private bool isRoot = true; //used to enforce calling Init() on children
private bool hasGrowthBehavior = false;
@@ -115,12 +115,10 @@ public bool Branch()
branch1.Init(childDepth, Random.Range (minBranchAngle, maxBranchAngle), treePiece.endWidthRatio);
}
- /*
if (branch2 == null) {
branch2 = Instantiate(this, branchLoc, transform.rotation) as ProceduralTreeSegment;
branch2.Init(childDepth, Random.Range (minBranchAngle, maxBranchAngle) * -1f, treePiece.endWidthRatio);
}
- */
branched = true;
// renderer.material.color = new Color(139 / 255f, 100 / 255f, 19 / 255f, renderer.material.color.a); //DEVEL
@@ -130,6 +128,18 @@ public bool Branch()
return true;
}
+
+ public int DepthLevel {
+ get {
+ return depthLevel;
+ }
+ }
+
+ public int MaxDepth {
+ get {
+ return maxDepth;
+ }
+ }
void OnMouseUp()
{
View
20 Assets/Scripts/Dance/TreeScripts/TreePieceMeshMaker.cs
@@ -10,7 +10,7 @@ public class TreePieceMeshMaker : MonoBehaviour
//note: only update the shape from ProceduralTreeSegment
void Start ()
{
- Mesh mesh = new Mesh ();
+ Mesh mesh = new Mesh();
GetComponent<MeshFilter>().mesh = mesh;
meshCollider = GetComponent<MeshCollider>();
}
@@ -22,16 +22,16 @@ void Update ()
int[] newTriangles = new int[6];
Mesh mesh = GetComponent<MeshFilter>().mesh;
- mesh.Clear ();
+ mesh.Clear();
float startMidPointXCoord = 0.5f;
float endMidPointXCoord = 0.5f * endWidthRatio;
// bottom left, bottom right, top left, top right
- newVertices[0] = new Vector3 (-startMidPointXCoord, 0, 0);
- newVertices[1] = new Vector3 (startMidPointXCoord, 0, 0);
- newVertices[2] = new Vector3 (endMidPointXCoord, 1.0f, 0);
- newVertices[3] = new Vector3 (-endMidPointXCoord, 1.0f, 0);
+ newVertices[0] = new Vector3(-startMidPointXCoord, 0, 0);
+ newVertices[1] = new Vector3(startMidPointXCoord, 0, 0);
+ newVertices[2] = new Vector3(endMidPointXCoord, 1.0f, 0);
+ newVertices[3] = new Vector3(-endMidPointXCoord, 1.0f, 0);
newTriangles[0] = 0;
newTriangles[1] = 1;
@@ -41,10 +41,10 @@ void Update ()
newTriangles[4] = 2;
newTriangles[5] = 3;
- newUV[0] = new Vector2 (0, 0);
- newUV[1] = new Vector2 (0, 1);
- newUV[2] = new Vector2 (1, 1);
- newUV[3] = new Vector2 (1, 0);
+ newUV[0] = new Vector2(0, 0);
+ newUV[1] = new Vector2(0, 1);
+ newUV[2] = new Vector2(1, 1);
+ newUV[3] = new Vector2(1, 0);
mesh.vertices = newVertices;
mesh.uv = newUV;
Please sign in to comment.
Something went wrong with that request. Please try again.