創(chuàng)建預(yù)設(shè)使用Resources.Load加載預(yù)設(shè)資源到場(chǎng)景
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 () {
}
}