File tree Expand file tree Collapse file tree 3 files changed +439
-211
lines changed
ButtonSoundsEditor/Assets/Plugins/ButtonSoundsEditor Expand file tree Collapse file tree 3 files changed +439
-211
lines changed Original file line number Diff line number Diff line change 1
- using UnityEngine ;
1
+ using System . Linq ;
2
+ using UnityEngine ;
3
+ using UnityEngine . EventSystems ;
2
4
using UnityEngine . UI ;
3
5
4
6
namespace Assets . Plugins . ButtonSoundsEditor
5
7
{
6
- [ RequireComponent ( typeof ( Button ) ) ]
7
8
public class ButtonClickSound : MonoBehaviour
8
9
{
9
10
public AudioSource AudioSource ;
10
11
public AudioClip ClickSound ;
11
12
12
13
public void Awake ( )
13
14
{
14
- GetComponent < Button > ( ) . onClick . AddListener ( PlayClickSound ) ;
15
+ Button button = GetComponent < Button > ( ) ;
16
+ if ( button != null )
17
+ {
18
+ button . onClick . AddListener ( PlayClickSound ) ;
19
+ }
20
+
21
+ EventTrigger eventTrigger = GetComponent < EventTrigger > ( ) ;
22
+ if ( eventTrigger != null )
23
+ {
24
+ EventTrigger . Entry clickEntry = eventTrigger . triggers . SingleOrDefault ( _ => _ . eventID == EventTriggerType . PointerClick ) ;
25
+ if ( clickEntry != null )
26
+ clickEntry . callback . AddListener ( _ => PlayClickSound ( ) ) ;
27
+ }
15
28
}
16
29
17
30
private void PlayClickSound ( )
You can’t perform that action at this time.
0 commit comments