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 () {
    
    }
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 初步整理并且学习unity3d资源加载方法,预计用时两天完成入门学习Unity3d常用两种加载资源方案:Resou...
    狼之独步阅读 10,063评论 1 2
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,868评论 18 139
  • Unity3D 里有两种动态加载机制:一个是Resources.Load,另外一个通过AssetBundle,其实...
    IongX阅读 1,731评论 0 5
  • 九月份的西安,已经过了”热死人”的季节,街边的梧桐树 老影院 死辣死辣的辣白菜 骑电瓶车的帅小哥 还有夜晚的烧烤...
    泖噜阅读 240评论 0 2
  • 10:00观察:1.早上5:45起床的,按照计划时间晚了,所以立马调整,所以早上的计划都完成。2.心里还是有...
    徐丽红阅读 192评论 0 0