41 lines
921 B
C#
41 lines
921 B
C#
|
using UnityEngine;
|
|||
|
using System.Collections;
|
|||
|
|
|||
|
public class DisableGameObj : MonoBehaviour {
|
|||
|
|
|||
|
public enum Operation
|
|||
|
{
|
|||
|
Disable,
|
|||
|
Destroy,
|
|||
|
}
|
|||
|
|
|||
|
public Operation m_Operation = Operation.Disable;
|
|||
|
public float DisableObjTimeSpace = 1.0f;
|
|||
|
private float lastenableTime;
|
|||
|
|
|||
|
// Use this for initialization
|
|||
|
void OnEnable () {
|
|||
|
|
|||
|
lastenableTime = Time.time;
|
|||
|
}
|
|||
|
public void ReEnable()
|
|||
|
{
|
|||
|
lastenableTime = Time.time;
|
|||
|
}
|
|||
|
// Update is called once per frame
|
|||
|
void Update () {
|
|||
|
|
|||
|
if(Time.time - lastenableTime > DisableObjTimeSpace)
|
|||
|
{
|
|||
|
if(m_Operation == Operation.Disable)
|
|||
|
gameObject.SetActive(false);
|
|||
|
else if(m_Operation == Operation.Destroy)
|
|||
|
{
|
|||
|
transform.SetParent(null);
|
|||
|
gameObject.SetActive(false);
|
|||
|
GameObject.Destroy(gameObject);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|