|
- using System;
- using SUISSEngine;
- using UnityEngine;
-
- [RequireComponent(typeof(BoxCollider2D), typeof(Rigidbody2D), typeof(AudioSource))]
- [RequireComponent(typeof(Clickable))]
- public class CIGPlayOnClick : MonoBehaviour
- {
- private void Awake()
- {
- this._audioSource = base.GetComponent<AudioSource>();
- }
-
- private void Start()
- {
- base.GetComponent<Rigidbody2D>().isKinematic = true;
- base.GetComponent<Collider2D>().isTrigger = true;
- if (this.clickable != null)
- {
- this.clickable.OnClickEvent += this.OnClickEvent;
- }
- }
-
- private void OnDestroy()
- {
- if (this.clickable != null)
- {
- this.clickable.OnClickEvent -= this.OnClickEvent;
- }
- }
-
- private void OnClickEvent(GameObject target)
- {
- if (Singleton<CIGSettings>.Instance.SoundEffectsEnabled && this.SoundFx != null)
- {
- this._audioSource.PlayOneShot(this.SoundFx);
- }
- }
-
- [SerializeField]
- private AudioClip SoundFx;
-
- [SerializeField]
- [SelfReference]
- private Clickable clickable;
-
- private AudioSource _audioSource;
- }
|