-
Notifications
You must be signed in to change notification settings - Fork 0
/
Item.cs
58 lines (53 loc) · 1.93 KB
/
Item.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
using UnityEngine;
public class Item : MonoBehaviour
{
public string type = "nothing";
public int amount;
public GameObject billboard;
private StateManager stateManager;
private GameManager gameManager;
public Vector3 startPosition;
//! Called by unity engine on start up to initialize variables.
public void Start()
{
billboard.GetComponent<Renderer>().enabled = false;
stateManager = FindObjectOfType<StateManager>();
gameManager = FindObjectOfType<GameManager>();
}
//! Called once per frame by unity engine.
public void Update()
{
if (!stateManager.Busy())
{
if (type != "nothing")
{
TextureDictionary td = gameManager.GetComponent<TextureDictionary>();
if (td != null)
{
if (td.dictionary != null)
{
if (td.dictionary.ContainsKey(type + "_Icon"))
{
billboard.GetComponent<Renderer>().material.mainTexture = td.dictionary[type + "_Icon"];
billboard.GetComponent<Renderer>().enabled = true;
}
else if (td.dictionary.ContainsKey(type))
{
billboard.GetComponent<Renderer>().material.mainTexture = td.dictionary[type];
billboard.GetComponent<Renderer>().enabled = true;
}
}
}
}
transform.Rotate(transform.up * 100 * Time.deltaTime);
}
}
//! Items fall to the ground faster than gravity would allow otherwise.
public void FixedUpdate()
{
if (!Physics.Raycast(transform.position, -Vector3.up, out RaycastHit hit, 1))
{
GetComponent<Rigidbody>().AddForce(-Vector3.up * 5000);
}
}
}