I want create sprite but not use UISprite but UITexture because this image to large for create sprite.
so i create code like this to make sprite image and use UITexture and when i create code like this, UITexture not update. Is this problem because UITexture cannot change texture in quick time or my script problem.
This is my code.
using UnityEngine;
using System.Collections;
public class SpriteGameEnded : MonoBehaviour {
public Texture2D mTexTemp;
public Texture2D mTex;
string path ="GameEnded";
int numberDigit = 2;
public UITexture uiTexture;
void Awake(){
uiTexture=GetComponent<UITexture>();
}
void OnEnable(){
object[] param
=new object[3]; param[0]=25;
param[1]=path;
param[2]=numberDigit;
StartCoroutine("PlayVideo",param);
if(audio!=null) audio.Play();
}
void OnDisable(){
mTex=mTexTemp;
if(audio!=null && audio.isPlaying) audio.Stop();
}
void Update(){
uiTexture.mainTexture=mTex;
}
IEnumerator PlayVideo(object[] param){
int fps =(int) param[0] ;
string path = (string) param[1];
int numberDigits = (int) param[2];
int i = 0;
bool done = false;
yield return new WaitForSeconds
(0
.5f
); int allImages = Resources.LoadAll<Texture2D>(path).Length-1;
while(!done){
string digits="";
if(i > allImages){
done = true;
break;
}
if(i < 10 && i >= 0){
for(int w = 0; w < numberDigits-1; w++){
digits = digits + "0";
}
digits = digits + i;
}
if(i < 100 && i >= 10){
for(int x = 0; x < numberDigits-2; x++){
digits = digits + "0";
}
digits = digits + i;
}
if (i < 1000 && i >= 100){
for(int y = 0; y < numberDigits-3; y++){
digits = digits + "0";
}
digits = digits + i;
}
if (i < 10000 && i >= 1000){
for(int z = 0; z < numberDigits-4; z++){
digits = digits + "0";
}
digits = digits + i;
}
string currentFile = path+"/"+path+digits;
Texture2D videoTexture = Resources.Load(currentFile)as Texture2D;
mTex = videoTexture;
i++;
yield return new WaitForSeconds
(1
.0f
/fps
); }
}
}