zoukankan      html  css  js  c++  java
  • u3d静态函数

    using UnityEngine;
    using System.Collections;
    
    public class Manager : MonoBehaviour
    {
        private static  Manager m_Instance;
    
        public static Manager instance
        {
            get
            {
                return m_Instance;
            }
        }
        // Use this for initialization
        void Start ()
        {
            m_Instance = this;
        }
    
        public void Gprint()
        {
            Debug.Log("Gprint");
        }
    
        public static void print()
        {
    
            Debug.Log("this is Manager");
        }
    
        // Update is called once per frame
        void Update ()
        {
    
            
    
        }
    }

    下面脚本调用

    using UnityEngine;
    using System.Collections;
    
    public class test : MonoBehaviour 
    {
    
        private Manager maager;
        void Start () 
        {
            
        }
        
        // Update is called once per frame
        void Update ()
        {
            maager = Manager.instance;
            maager.Gprint();
            Manager.print();
        
        }
    
       
    
        void OnGUI()
        {
           // GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), tex);
           
        }
    }
     maager = Manager.instance; 放到update里面,是因为每个脚本的Start执行时间不一样,不能确保manager的start就一定在Test类的前面执行,所以放到update里面更保险
    类的成员函数就使用得到的,静态的方法使用类的头
  • 相关阅读:
    基于ARP的网络扫描工具netdiscover
    渗透测试集成环境Faraday
    NBNS扫描工具nbtscan-unixwiz
    分享Kali Linux 2017年第18周镜像文件
    Hat's Fibonacci
    N!
    A + B Problem II(大数加法)
    产生冠军(拓扑排序)
    确定比赛名次
    Legal or Not(模板题)
  • 原文地址:https://www.cnblogs.com/dragon2012/p/4025931.html
Copyright © 2011-2022 走看看