chunk 1: core gameplay scripts scenes runtime assets
This commit is contained in:
16
Assets/Scripts/Button Click/ButtonClickDetector.cs
Normal file
16
Assets/Scripts/Button Click/ButtonClickDetector.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class ButtonClickDetector : MonoBehaviour, IPointerClickHandler
|
||||
{
|
||||
public UnityEvent onClick;
|
||||
|
||||
public bool Clicked { get; set; }
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
Clicked = true;
|
||||
onClick.Invoke();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Button Click/ButtonClickDetector.cs.meta
Normal file
11
Assets/Scripts/Button Click/ButtonClickDetector.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bee16f2af4e522b4c82a66e80d442828
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
40
Assets/Scripts/Button Click/ButtonClickSound.cs
Normal file
40
Assets/Scripts/Button Click/ButtonClickSound.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ButtonClickSound : MonoBehaviour
|
||||
{
|
||||
public AudioClip clickSound;
|
||||
|
||||
private Button button;
|
||||
private AudioSource audioSource;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
button = GetComponent<Button>();
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
|
||||
// Create an AudioSource component if one doesn't already exist
|
||||
if (audioSource == null)
|
||||
{
|
||||
audioSource = gameObject.AddComponent<AudioSource>();
|
||||
}
|
||||
|
||||
// Set the AudioClip to play when the button is clicked
|
||||
audioSource.clip = clickSound;
|
||||
|
||||
// Make sure the AudioSource doesn't play automatically
|
||||
audioSource.playOnAwake = false;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// Attach the button click event to the PlayClickSound() method
|
||||
button.onClick.AddListener(PlayClickSound);
|
||||
}
|
||||
|
||||
public void PlayClickSound()
|
||||
{
|
||||
// Play the click sound using the Manager
|
||||
GameManager.Instance.PlaySound(clickSound);
|
||||
}
|
||||
}
|
||||
12
Assets/Scripts/Button Click/ButtonClickSound.cs.meta
Normal file
12
Assets/Scripts/Button Click/ButtonClickSound.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d4618d29e8ff4346b4cf90d10e23bb8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- clickSound: {fileID: 8300000, guid: 712edf32f2eaf0247abd5118428699d2, type: 3}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user