Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class soundOnTrigger: MonoBehaviour
- {
- public AudioClip soundToPlay;
- private AudioSource audioSource;
- private void Start()
- {
- audioSource = GetComponent<AudioSource>();
- if (audioSource == null)
- {
- audioSource = gameObject.AddComponent<AudioSource>();
- }
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.CompareTag("Player"))
- {
- // Проверяем, что соприкоснулся игрок
- if (soundToPlay != null)
- {
- audioSource.PlayOneShot(soundToPlay);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement