-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColorChangeOnTrigger.cs
97 lines (80 loc) · 2.42 KB
/
ColorChangeOnTrigger.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using UnityEngine;
public class ColorChangeOnTrigger : MonoBehaviour
{
private SpriteRenderer spriteRenderer1;
//public string currentcolor;
public Sprite Pressed;
public Sprite Released;
//public AudioClip ToggleSound;
public int PplOnButton = 0;
public bool IsPressed = false;
private void FixedUpdate()
{
if(PplOnButton <= 0)
{
spriteRenderer1.sprite = Released;
}
else
{
spriteRenderer1.sprite = Pressed;
}
//
}
void Start()
{
// Get the SpriteRenderer component attached to the rectangle GameObject
spriteRenderer1 = GetComponent<SpriteRenderer>();
// Set the initial color of the rectangle
spriteRenderer1.sprite = Released;
//currentcolor = "red";
}
// Called when another Collider2D enters the trigger area
void OnTriggerEnter2D(Collider2D other)
{
// Check if the object entering the trigger is the one you're interested in (e.g., player)
if (other.CompareTag("Human") || other.CompareTag("Boulder"))
{
PplOnButton++;
if(PplOnButton == 1)
{
if (FindObjectOfType<AudioManager>() != null)
{
FindObjectOfType<AudioManager>().Play("Button");
}
IsPressed = true;
}
//CalculateButton();
//Toggle(true);
}
}
// Called when another Collider2D exits the trigger area
void OnTriggerExit2D(Collider2D other)
{
// Check if the object exiting the trigger is the one you're interested in (e.g., player)
if (other.CompareTag("Human") || other.CompareTag("Boulder"))
{
//Toggle(false);
PplOnButton--;
if(PplOnButton == 0)
{
if (FindObjectOfType<AudioManager>() != null)
{
FindObjectOfType<AudioManager>().Play("Button");
}
IsPressed = false;
}
//CalculateButton();
}
}
public void CalculateButton()
{
if (PplOnButton <= 0)
{
IsPressed = false;
}
if(PplOnButton > 0)
{
IsPressed = false;
}
}
}