Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Networking;
- using UnityEngine.UI;
- public class Test : MonoBehaviour
- {
- [SerializeField] Image refImage;
- AudioSource refSource;
- private void Awake()
- {
- refSource = GetComponent<AudioSource>();
- }
- private void Start()
- {
- StartCoroutine(LoadLocalTexture(Application.streamingAssetsPath+"/img.png",refImage));
- StartCoroutine(LoadLocalAudio(Application.streamingAssetsPath + "/V1C_86.wav",refSource));
- }
- public IEnumerator LoadLocalTexture(string path, Image receivingImage)
- {
- UnityWebRequest www = UnityWebRequestTexture.GetTexture(path);
- yield return www.SendWebRequest();
- if (www.isNetworkError || www.isHttpError)
- {
- Debug.Log(www.error);
- }
- else
- {
- Texture2D myTexture = DownloadHandlerTexture.GetContent(www);
- receivingImage.sprite = Sprite.Create(myTexture, new Rect(0.0f, 0.0f, myTexture.width, myTexture.height), new Vector2(0f, 0f));
- Debug.Log(receivingImage.name);
- }
- }
- public IEnumerator LoadLocalAudio(string path, AudioSource receivingAudio)
- {
- UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(path, AudioType.WAV);
- yield return www.SendWebRequest();
- if (www.isNetworkError || www.isHttpError)
- {
- Debug.Log(www.error);
- }
- else
- {
- var audioClip = DownloadHandlerAudioClip.GetContent(www);
- audioClip.name = "Hey come on come on !";
- receivingAudio.clip = audioClip;
- receivingAudio.Play();
- Debug.Log(receivingAudio.clip.name);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement