Resources.Load 加载预设资源 Prefabs

创建预设使用Resources.Load加载预设资源到场景

using UnityEngine;
using System.Collections;

public class loadLoadingUI : MonoBehaviour {

    // Use this for initialization
    void Start () {
        GameObject UIRoot = GameObject.FindWithTag("UIRoot");
        if (UIRoot != null)
        {
            Object SliderPrefab = Resources.Load("Prefabs/Slider") as Object;
            if (SliderPrefab != null)
            {
                GameObject Slider = Instantiate(SliderPrefab) as GameObject;
                //Slider.transform.parent = UIRoot.transform;
                //Slider.transform.localPosition = Vector3.zero;

                Slider.transform.SetParent(UIRoot.transform, false);
                Slider.transform.SetAsLastSibling();
    
            }
            else
            {
                Debug.Log("Failed to load prefab file");
            }
        }
        else
        {
            Debug.LogError("There is not a GameObject with tag UIRoot");
        }
    }
    
    // Update is called once per frame
    void Update () {
    
    }
}

你可能感兴趣的:(Resources.Load 加载预设资源 Prefabs)