美文网首页
动态加载图片资源

动态加载图片资源

作者: sconi | 来源:发表于2017-10-20 09:28 被阅读0次

    动态加载资源管理器的资源 就要在assets目录下 建立一个Resources文件夹 把要替换的源文件放到里面 然后用: 要改变值的物体.sprite= Resources.Load(“Resources的根目录”, typeof(Sprite)) as Sprite; //需要注意的是图片资源属性要改为Sprite精灵图片。

    实例:

    using UnityEngine;

    using System.Collections;

    using UnityEngine.UI;

    public class ChangeImage : MonoBehaviour {

    public Image fang; //需要修改的物体

    // Update is called once per frame

    void Update () {

    if(Input.GetKeyDown(KeyCode.Q))//按Q键

    {

    //将动态加载进来的图片赋值到fang.sprite,图片资源必须在Resources文件夹下

    fang.sprite = Resources.Load(“gaolin”, typeof(Sprite)) as Sprite;

    }

    }

    }

    相关文章

      网友评论

          本文标题:动态加载图片资源

          本文链接:https://www.haomeiwen.com/subject/youmuxtx.html