- Home /
Link image sequence to an array
Hey guys, I tried to do a video with transparency but I got some problems, now I'm using an image sequence to do an animated texture by my self, I done the code, and its all working but I have 70 png's sequences to link one per one.
I'm using public Texture[] texture
Can I link a folder and get the images inside or any other solution to don't drag pngs one per one ?
Answer by robertbu · Jan 15, 2014 at 07:09 PM
If you take a look at the Unity Interface, you will see a tiny lock icon at the top right of the Inspector opposite the 'Inspector' tab. To load all of your images at once:
Select the game object with the above script
Click on the 'lock' icon to lock the veiw
Go to your textures and select the ones you want
Drag and drop the whole list to the 'texture' variable
Click on the 'lock' icon again to unlock the view
I found a problem, Unity is not displacing them in order, for example, the images are named 01,02,03,04 and unity put 02,01,04,06
You are absolutely right. I've never used this feature for exactly this purpose. It seems like a bug to be for it to function this way. The only thing I can think of to work around the problem is Resources.Load() or Resources.LoadAll(). Put all of your images in a folder in the Assets/Resources folder. Then you can do:
void Start() {
texture = Resources.LoadAll<Texture>("theTextures");
}
...where 'theTextures' is the name of the folder inside of 'Resources' where you placed your images.
Answer by Fred_Vicentin · Jan 16, 2014 at 12:28 PM
I'm posting there to help everyone that have the same problem. I done some modifications on my code, this is a code that pass texture per texture like a MovieTexture, you can use it when you need a transparency on your video.
Code:
using UnityEngine;
using System.Collections;
public class gifAnimate : MonoBehaviour
{
//Can't be Texture, you need create an Object and later convert in Texture
public Object[] botao;
//Change this for speed
public float framesPerSecond = 10;
void Start()
{
//Change "MaoEsquerda" for the Folder name (thanks robertbu)
botao = Resources.LoadAll("MaoEsquerda");
}
void Update()
{
int index = (int) (Time.time * framesPerSecond) % botao.Length;
//Now you convert the Object to texture
renderer.material.mainTexture = botao[index] as Texture;
}
}
Remember that you need to create a folder called Resources and put a folder with the name that you want, on my case, "MaoEsquerda". Enjoy =)
Your answer
Follow this Question
Related Questions
Cycling Texture Array 1 Answer
How to access multiple components of a component at once? 2 Answers
How can i show the texture in the array? 2 Answers
Textures from array variabels? 1 Answer
Assigning UV Map to model at runtime 0 Answers