Unity3d Resources.load Dynamically loading resources

Source: Internet
Author: User

Preliminary finishing and learning Unity3d Resource loading method, estimated to take two days to complete the introductory learning

Unity3d Common Two load resource scenarios:resources.load and assetbundle

Resources.load is to load resources from a assetbundle in the default package.

While the general assetbundle file needs to be created yourself, the runtime dynamically loads and can specify the path and source. In fact, all the static objects in the scene also have such a loading process, but Unity backstage for you to automatically complete

A:resources.load: Use this method to load resources, first need to Create a folder named Resources under the Asset directory , This naming is the way the u3d , and then the resource file is put in,

of course, you can also Resources And, of course, you need to add the appropriate resource path when the code loads, and here's a simple Demo , two presets,

Cube and the Sphere , where Cube placed in Resource in the Prebs in, and Sphere placed in Resources under Directory, the following separately implements the loading of resources.load resources

Using Unityengine;
Using System.Collections;

public class Loadresdemo:monobehaviour {

private string Cubepath = "Prebs/mycubepreb";
private string Spherepath = "Myspherepreb";
void Start () {
Load Resources into memory
Object Cubepreb = Resources.load (Cubepath, typeof (Gameobject));
Using the loaded resource object, instantiate the game object, realize the dynamic loading of the game object.
Gameobject cube = Instantiate (Cubepreb) as Gameobject;

The following is a similar implementation of dynamic instantiation of sphere
Load Resources into memory
Object Spherepreb = Resources.load (Spherepath, typeof (Gameobject));
Using the loaded resource object, instantiate the game object, realize the dynamic loading of the game object.
Gameobject sphere = Instantiate (Spherepreb) as Gameobject;
}

}

Unity3d Resources.load Dynamically loading resources

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.