public scripts
A downloadable asset pack
using UnityEngine;
using easyInputs;
public class BButtonToggle : MonoBehaviour
{
[Header("Object to Toggle")]
public GameObject targetObject;
[Header("Cooldown")]
public float toggleCooldown = 1f;
[Header("Audio")]
public AudioSource audioSource;
public AudioClip enabledSound;
public AudioClip disabledSound;
private float nextToggleTime = 0f;
void Update()
{
if (Time.time >= nextToggleTime &&
EasyInputs.GetSecondaryButtonDown(EasyHand.RightHand))
{
if (targetObject != null)
{
bool newState = !targetObject.activeSelf;
targetObject.SetActive(newState);
if (audioSource != null)
{
if (newState && enabledSound != null)
{
audioSource.PlayOneShot(enabledSound);
}
else if (!newState && disabledSound != null)
{
audioSource.PlayOneShot(disabledSound);
}
}
nextToggleTime = Time.time + toggleCooldown;
}
}
}
}
| Published | 13 days ago |
| Status | Released |
| Category | Assets |
| Author | TPACUPID |
| Content | No generative AI was used |
Leave a comment
Log in with itch.io to leave a comment.