/
KeyHolder.cs
60 lines (54 loc) · 1.52 KB
/
KeyHolder.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
58
59
60
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using UnityEngine;
public class KeyHolder : MonoBehaviour
{
//Lista typów kluczy
//List with KeysType
private List<Key.KeysTypes> keyslist;
private void Awake()
{
keyslist = new List<Key.KeysTypes>();
}
//Dodawanie kluczy
//Add keys
public void Add(Key.KeysTypes keysTypes)
{
Debug.Log("ADD" + keysTypes);
keyslist.Add(keysTypes);
}
//Usuwanie
//Remove
public void Remove(Key.KeysTypes keysTypes)
{
keyslist.Remove(keysTypes);
}
//Sprawdzamy czy lista kluczy zawiera określony klucz
//We chack that the list have true value with keys
public bool Contains(Key.KeysTypes keysTypes)
{
return keyslist.Contains(keysTypes);
}
//Give the trigger
private void OnTriggerEnter2D(Collider2D collision)
{
Key key = collision.GetComponent<Key>();
if(key != null)
{
Add(key.GetTypes());
Destroy(key.gameObject);
}
DoorWithKey doorWithKey = collision.GetComponent<DoorWithKey>();
if(doorWithKey != null)
{
if(Contains(doorWithKey.GetTypes()))
{
//Trzymamy klucz do otwarcia drzwi
//Holding key to open the door
Remove(doorWithKey.GetTypes());
doorWithKey.OpenDoor();
}
}
}
}