Advertisement
fuccpuff

Untitled

Dec 27th, 2023
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class soundOnTrigger: MonoBehaviour
  4. {
  5. public AudioClip soundToPlay;
  6. private AudioSource audioSource;
  7.  
  8. private void Start()
  9. {
  10. audioSource = GetComponent<AudioSource>();
  11. if (audioSource == null)
  12. {
  13. audioSource = gameObject.AddComponent<AudioSource>();
  14. }
  15. }
  16.  
  17. private void OnTriggerEnter(Collider other)
  18. {
  19. if (other.CompareTag("Player"))
  20. {
  21. // Проверяем, что соприкоснулся игрок
  22. if (soundToPlay != null)
  23. {
  24. audioSource.PlayOneShot(soundToPlay);
  25. }
  26. }
  27. }
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement