You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
615 B
C#
30 lines
615 B
C#
2 weeks ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
|
||
|
public class ButtonSoundClick : MonoBehaviour
|
||
|
{
|
||
|
public AudioSource audioSource;
|
||
|
public Button[] allButtons;
|
||
|
private void Start()
|
||
|
{
|
||
|
Starter();
|
||
|
}
|
||
|
void Starter()
|
||
|
{
|
||
|
allButtons = FindObjectsOfType<Button>(true);
|
||
|
for (int i = 0; i < allButtons.Length; i++)
|
||
|
{
|
||
|
allButtons[i].onClick.AddListener(() =>
|
||
|
{
|
||
|
PlayClickSound();
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
void PlayClickSound()
|
||
|
{
|
||
|
audioSource.Play();
|
||
|
}
|
||
|
}
|