unity3D 中的C#脚本一个类调用另一类中简单方法


案例展示

SubMenuManage类中的实例化代码如下:

 static SubMenuManage sub_this;

public static SubMenuManage Instance()
{
  if (sub_this == null)
  {
    sub_this = new SubMenuManage();
  }
  return sub_this;
}

其他类中调用SubMenuManage类中的函数代码如下:

SubMenuManage.Instance().StartData(paraSet);

总结如下:

在A类中编写实例化A类的函数

static  A(类的名字) A_this;
public static A Instance()
{
  if (A_this == null)
  {
    A_this = new A();
  }
  return A_this;
}

在其他类中调用A类中的内容代码

A.Instance().[A 类中的函数、变量等参数];

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM