Blogger Information
Blog 95
fans 0
comment 11
visits 249422
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Unity3d中C#脚本调用另一个C#脚本的方法
龍__遇见彩虹的博客
Original
8727 people have browsed it

*****第一个脚本名字为Class_1,第二个脚本名字为Class_2*****


**Class_1调用Class_2**

  1. GameObject.Find("脚本所在物体名").GetComponent<脚本名>().函数名();此种方法只可以调用public类型函数。

如果Class_2没有绑定在任何GameObject上,那在Class_1里写法:
Class_2 c2 = new Class_2();

如果Class_2绑定在GameObject上,那在 Class_1里写法:

Class_2 c2 = null;
void Start()
{
   c2 = GameObject.Find("绑定的GameObject名字").GetComponent<Class_2>();
}



**Class_1调用Class_2的某个函数或开关**

    2.被调用脚本函数为static类型,调用时直接用  脚本名.函数名()。

首先Class_2里定义个bool值函数:public static bool isMove = false;

那么Class_1调用就是:Class_2.isMove


3.GameObject.Find("脚本所在物体名").SendMessage("函数名");  此种方法可以调用public和private类型函数。

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post