-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModBlock.cs
50 lines (46 loc) · 1.64 KB
/
ModBlock.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
using UnityEngine;
public class ModBlock : Block
{
private Material material;
private StateManager stateManager;
private PlayerController playerController;
private GameManager gameManager;
public GameObject glassBreak;
private bool init;
public string ID = "unassigned";
public string blockName;
//! Called by unity engine on start up to initialize variables.
public void Start()
{
material = new Material(Shader.Find("Standard"));
gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
playerController = GameObject.Find("Player").GetComponent<PlayerController>();
stateManager = gameManager.GetComponent<StateManager>();
}
//! Called once per frame by unity engine.
public void Update()
{
if (!stateManager.Busy() && init == false)
{
BlockDictionary blockDictionary = playerController.GetComponent<BuildController>().blockDictionary;
if (blockDictionary.meshDictionary.ContainsKey(blockName))
{
GetComponent<MeshFilter>().mesh = blockDictionary.meshDictionary[blockName];
}
gameManager.meshManager.SetMaterial(gameObject, blockName);
if (blockName.ToUpper().Contains("GLASS"))
{
GetComponent<PhysicsHandler>().explosion = glassBreak;
}
init = true;
}
}
//! Called by BlockManager update coroutine.
public override void UpdateBlock()
{
if (ID == "unassigned" || stateManager.Busy())
{
GetComponent<PhysicsHandler>().UpdatePhysics();
}
}
}