ShanxiKnowledgeBase/SXElectricalInspection/Assets/Script/MyFrameworkPure/Compoent/OnlyOne.cs

24 lines
475 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MyFrameworkPure
{
/// <summary>
/// 保证场景中物体唯一
/// </summary>
public class OnlyOne : MonoBehaviour
{
private static OnlyOne instance;
void Awake()
{
if (instance == null)
instance = this;
else if (instance != this)
DestroyImmediate(gameObject);
}
}
}