HotPlate.cs
1.84 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HotPlate : MonoBehaviour
{
public GameObject plates; // this oven has 4 hot plates
public bool activePlateIndices = false;
public GameObject canHeatObjectsOnMe;
private void Start()
{
}
// Update is called once per frame
void Update()
{
// check if user switchs on or off one of plates
plates.transform.GetChild(0).gameObject.SetActive(true);
activePlateIndices = true;
if (canHeatObjectsOnMe)
{
if (canHeatObjectsOnMe.GetComponent<CanCook>())
{
canHeatObjectsOnMe.GetComponent<CanCook>().canCook = true;
}
}
else
{
plates.transform.GetChild(0).gameObject.SetActive(false);
activePlateIndices = false;
if (canHeatObjectsOnMe)
{
if (canHeatObjectsOnMe.GetComponent<CanCook>())
{
canHeatObjectsOnMe.GetComponent<CanCook>().canCook = false;
}
}
}
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.GetComponent<CanCook>())
{
string name = collision.contacts[0].thisCollider.name;
canHeatObjectsOnMe = collision.gameObject;
canHeatObjectsOnMe.tag = "Fire";
}
}
private void OnCollisionExit(Collision collision)
{
if (canHeatObjectsOnMe == collision.gameObject)
{
canHeatObjectsOnMe.gameObject.tag = "NotFire";
canHeatObjectsOnMe = null;
if (collision.gameObject.GetComponent<CanCook>())
{
collision.gameObject.GetComponent<CanCook>().canCook = false;
}
}
}
}