summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Tag/Area.cs
blob: 196bd36111a91a65c3bdae8f4d01914f16fee85c (plain) (blame)
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
using System;
using System.Collections.Generic;
using UnityEngine;

namespace Tag
{
    public class Area : MonoBehaviour
    {
        public ItemType itemAccepted;
        public List<TagItem> items;

        private void OnTriggerEnter(Collider other)
        {
            if (other.CompareTag("Part"))
            {
                var obj = other.GetComponent<TagItem>();
                if (obj.info.itemType == itemAccepted)
                {
                    if (! items.Contains(obj))
                    {
                        items.Add(obj);
                    }
                }
            }
        }

        private void OnTriggerExit(Collider other)
        {
            if (other.CompareTag("Part"))
            {
                var obj = other.GetComponent<TagItem>();
                if (items.Contains(obj))
                {
                    items.Remove(obj);
                }
            }
        }
    }
}