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
43 lines
915 B
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
public class ObjectActivator : MonoBehaviour
|
|
{
|
|
public bool Toggle;
|
|
public UnityEvent OnActivated;
|
|
public UnityEvent OnDeactivated;
|
|
public AudioClip audioClip;
|
|
public AudioSource audioSource;
|
|
|
|
bool m_Activated = false;
|
|
|
|
public void Activated()
|
|
{
|
|
if (Toggle)
|
|
{
|
|
if (m_Activated)
|
|
OnDeactivated.Invoke();
|
|
else
|
|
OnActivated.Invoke();
|
|
m_Activated = !m_Activated;
|
|
audioSource.PlayOneShot(audioClip);
|
|
}
|
|
else
|
|
{
|
|
OnActivated.Invoke();
|
|
m_Activated = true;
|
|
|
|
}
|
|
}
|
|
|
|
public void Deactivated()
|
|
{
|
|
if (!Toggle)
|
|
{
|
|
OnDeactivated.Invoke();
|
|
m_Activated = false;
|
|
}
|
|
}
|
|
}
|