Unity中图片的调用

来源:互联网 发布:金融数据 驾驶仓 编辑:程序博客网 时间:2024/06/06 06:42
  1. 效果图
    在面板上生成需要的图片
  2. 将下面的脚本挂载到RawImage上
    这里写图片描述
using UnityEngine;using System.Collections;public class TestWWW : MonoBehaviour {    // Use this for initialization    void Start () {        StartCoroutine(WWWLoad());    }    // Update is called once per frame    void Update () {    }    IEnumerator WWWLoad()    {        string path = "file://" + Application.dataPath + @"\timg.jpg";        **\timg.jpg为要调用的图片名称**        Debug.Log(path);        WWW www = new WWW(path);        yield return www;        if (www.error != null)        {            Debug.Log(www.error);        }        if (www != null)        {            this.GetComponent<UnityEngine.UI.RawImage>().texture = www.texture;        }    }}
原创粉丝点击