SW 중심대학 OSS GIT 서버 새로운 리포
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
915 B

5 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Events;
  5. public class ObjectActivator : MonoBehaviour
  6. {
  7. public bool Toggle;
  8. public UnityEvent OnActivated;
  9. public UnityEvent OnDeactivated;
  10. public AudioClip audioClip;
  11. public AudioSource audioSource;
  12. bool m_Activated = false;
  13. public void Activated()
  14. {
  15. if (Toggle)
  16. {
  17. if (m_Activated)
  18. OnDeactivated.Invoke();
  19. else
  20. OnActivated.Invoke();
  21. m_Activated = !m_Activated;
  22. audioSource.PlayOneShot(audioClip);
  23. }
  24. else
  25. {
  26. OnActivated.Invoke();
  27. m_Activated = true;
  28. }
  29. }
  30. public void Deactivated()
  31. {
  32. if (!Toggle)
  33. {
  34. OnDeactivated.Invoke();
  35. m_Activated = false;
  36. }
  37. }
  38. }