unity controller single 写法

private static RetroSnakerController _Instance;
        public static RetroSnakerController Instance
        {
            get
            {
                if (_Instance == null)
                {
                    var manipulationSystems = FindObjectsOfType();
                    if (manipulationSystems.Length > 0)
                    {
                        _Instance = manipulationSystems[0];
                    }
                    else
                    {
                        Debug.LogError("No instance of ManipulationSystem exists in the scene.");
                    }
                }

                return _Instance;
            }
        }
        
public static FoodController Instance;
private void Awake()
        {
            // if the singleton hasn't been initialized yet
            if (Instance== null)
                Instance= this;
        }

你可能感兴趣的:(Unity,unity)