U3D notes (1)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.