using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class LoadImage : MonoBehaviour { Texture2D tempImage; private RawImage RawImageRef; // Use this for initialization void Start () { RawImageRef = gameObject.GetComponent(); StartCoroutine(OnLoadImage("uploadFile/projectImg/22.jpg", RawImageRef)); } // Update is called once per frame void Update () { } IEnumerator OnLoadImage(string path, RawImage image) { string filePath = "file://" + Application.persistentDataPath + "/document/" + path; //string filePath = "file://" + "/sdcard/TKData/SaveData/" + "document/" + path;//手机 WWW www = new WWW(filePath); yield return www; if (www.error != null) { Debug.LogError(filePath + www.error); image.gameObject.SetActive(false); } else { Debug.LogError(filePath); image.gameObject.SetActive(true); tempImage = www.texture; image.texture = tempImage; } } }

将图片放入本地指定文件夹即可

unity设置如下

af06d9f4e7a97eebd99025197125975f.png

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐