-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButtonHoldObject.cs
48 lines (45 loc) · 1.13 KB
/
ButtonHoldObject.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ButtonHoldObject : MonoBehaviour {
public GameObject LeverObject;
public Sprite UnPressed;
public Sprite Pressed;
public bool RequiresPressable;
private SpriteRenderer SR;
public int ObjectsInside;
private void Start()
{
SR = GetComponent<SpriteRenderer>();
}
void OnTriggerEnter2D(Collider2D other)
{
if (RequiresPressable)
{
if(other.tag == "CanPress")
ObjectsInside++;
}
else
ObjectsInside++;
if (ObjectsInside > 0)
{
SR.sprite = Pressed;
LeverObject.SetActive(false);
}
}
void OnTriggerExit2D(Collider2D other)
{
if (RequiresPressable)
{
if (other.tag == "CanPress")
ObjectsInside--;
}
else
ObjectsInside--;
if (ObjectsInside <= 0)
{
SR.sprite = UnPressed;
LeverObject.SetActive(true);
}
}
}