Set an object as a sub-object of another object----Nguitools.addchild () method

Source: Internet
Author: User

usingUnityengine;usingSystem.Collections; Public classLoadprefab:monobehaviour {//declare a reference to this object, and Uiroot will create a sub-object under this object later .     PublicGameobject Uiroot; //declares the name of the child object preset to be loaded    stringPrefabname ="Template"; voidStart () {if(Uiroot! =NULL)        {             //the preset is loaded into memory according to the path as a gameobject existsGameobject go = Resources.load ("ui/"+ prefabname) asGameobject; //hanging sub-objects using the Nguitools.addchild methodGameobject NEWOBJ =Nguitools.addchild (Uiroot,go); /*Method 2 * Gameobject NewObj2 = Instantiate (go, uiRoot.transform.position, uiRoot.transform.rotation) as Gameobj            ect            NewObj2.transform.parent = Uiroot.transform; */            //the name of the new object can be printed outDebug.Log ("the newborn becomes a sub-object called:"+newobj.name); }    }        //Update is called once per frame    voidUpdate () {}}

Set an object as a sub-object of another object----Nguitools.addchild () method

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.