You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/Feel/MMTools/Tools/MMActivation/MMToggleActive.cs

39 lines
992 B
C#

3 months ago
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// This very simple class simply exposes a method to toggle the GameObject it's on (or a target one if left empty in the inspector) active or inactive
/// </summary>
public class MMToggleActive : MonoBehaviour
{
[Header("Target - leave empty for self")]
/// the target gameobject to toggle. Leave blank for auto grab
public GameObject TargetGameObject;
/// a test button
[MMInspectorButton("ToggleActive")]
public bool ToggleActiveButton;
/// <summary>
/// On awake, grabs self if needed
/// </summary>
protected virtual void Awake()
{
if (TargetGameObject == null)
{
TargetGameObject = this.gameObject;
}
}
/// <summary>
/// Toggles the target gameobject's active state
/// </summary>
public virtual void ToggleActive()
{
TargetGameObject.SetActive(!TargetGameObject.activeInHierarchy);
}
}
}