-
Notifications
You must be signed in to change notification settings - Fork 0
/
Renderer
44 lines (40 loc) · 1.58 KB
/
Renderer
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Renderer : MonoBehaviour
{
public static void RenderAllTrees(ForestFire forestFire, Material nonBurningTree, Material burningTree, Material deadTree, Vector2 showMorePos)
{
foreach (Tree treeBeingRendered in forestFire.listOfTrees)
{
GameObject treeRenderObject = GameObject.CreatePrimitive(PrimitiveType.Plane);
treeRenderObject.transform.position = treeBeingRendered.position.Vector2 + showMorePos;
treeRenderObject.transform.localRotation = Quaternion.Euler(-90, 0, 0);
treeRenderObject.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
MeshRenderer treeRenderObjectMeshRenderer = treeRenderObject.GetComponent<MeshRenderer>();
if (treeBeingRendered.dead)
{
treeRenderObjectMeshRenderer.material = deadTree;
}
else if (treeBeingRendered.burning)
{
treeRenderObjectMeshRenderer.material = burningTree;
}
else
{
treeRenderObjectMeshRenderer.material = nonBurningTree;
}
treeRenderObject.tag = "TreeObject";
treeRenderObject.name = (treeBeingRendered.treeId).ToString();
}
}
public static void DeleteAllRenders()
{
GameObject[] toDestoyTrees;
toDestoyTrees = GameObject.FindGameObjectsWithTag("TreeObject");
foreach (GameObject tree in toDestoyTrees)
{
DestroyImmediate(tree);
}
}
}