动态加载图片资源

2017-10-20  本文已影响0人  sconi

动态加载资源管理器的资源 就要在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;

}

}

}

上一篇下一篇

猜你喜欢

热点阅读