-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtonScript.cs
More file actions
49 lines (41 loc) · 1.15 KB
/
ButtonScript.cs
File metadata and controls
49 lines (41 loc) · 1.15 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ButtonScript : MonoBehaviour
{
public static bool pressing;
public MeshRenderer buttonMesh;
public Light buttonLight;
public Color PressedColor;
public AudioSource PressSound;
private Color initColor;
private Color initLightColor;
void Start()
{
initColor = GetComponent<MeshRenderer>().material.color;
initLightColor = buttonLight.color;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.U))
{
pressing = true;
buttonMesh.material.color = PressedColor;
buttonLight.color = PressedColor;
PressSound.Play();
}
}
void OnTriggerEnter(Collider other)
{
pressing = true;
buttonMesh.material.color = PressedColor;
buttonLight.color = PressedColor;
PressSound.Play();
}
void OnTriggerExit(Collider other)
{
pressing = false;
buttonMesh.material.color = initColor;
buttonLight.color = initLightColor;
}
}