1. Communication between scripts in the same GameObject in U3D: JS
Var other: JSB;
Key code: ① this. GameObject. GetComponent "JSB ");
② This. GameObject. GetComponent. <JSB> ();
③ This. GameObject. GetComponentJSB );
Function Start (){
Other = ①/②/③;
}
2. Script communication between different gameobjects in U3D
Key code: ①: var $ com: Transform;
Copy the game object GameObject to the variable $ com.
②: Var $ js: JSB
Copy the game object GameObject)-> JSB to $ js, because the GameObject contains JSB
③: Use: GameObject. Find) solution:
Var $ gameObject: GameObject;
Function Start (){
$ GameObject = GameObject. find ("Sphere ");
}
This scheme does not need to be assigned a value on the attribute panel.
④: Use: GameObject. FindGameObjectWithTag
Add Tag
Define variable: var $ gameObject: GameObject;
This article is from the "Better_Power_Wisdom" blog, please be sure to keep this source http://aonaufly.blog.51cto.com/3554853/1281180