using mainTexture changing to cheat a small movie playing...

Hi,

As yet I dont have the PRO version (although Im counting my pennies)
I need to use a short movie in my game demo, but cant yet use movie import… but I found a hack.
if I exprt my movie(tis but 50 frames) as seperate frames pngs, and then use THIS…

// Assign the texture exposed in the inspector the renderer's material
var texture : Texture;
renderer.material.mainTexture = texture;

// Change renderer's texture each changeInterval
// seconds from the texture array defined in the inspector.
var textures : Texture[];
var changeInterval = 0.33;

function Update() {
if( textures.length == 0 ) // nothing if no textures
return;

// we want this texture index now
var index : int = Time.time / changeInterval;
// take a modulo with size so that animation repeats
index = index % textures.length;
// assign it
renderer.material.mainTexture = textures[index];
}

to change the texture on a plane… i can get a small movie to run (not how I cleverly commented out one line to stop it from looping.

HOWEVER, using this method I have to define the number of elements, and then drag in EVERY frame to the Element slots.

OW!!!

Isnt it a peice of cake for a clever programmer type (not me) to do something like this where it can simply update the name of the texture used from Frame0001 to Frame0002, Frame0003.

can some nice person help me with the code for that?

Mark

C# code for looping through the names “Frame0000” to “Frame0049”. I am sure you won’t have trouble porting it to JS.

int numFrames = 50;
for (int i = 0; i < numFrames; ++i)
{
  string textureName = string.Format("Frame{0:0000}", i);
  Debug.Log(textureName);
}

… Or just drag the 50 frames by hand, it doesn’t take all day.

Er… well… not so sure about that… but thanks… i get the point… i think…

Mark[/code]

I am not 100% sure about JS but I think it is something like this:

var numFrames = 50;
for (var i = 0; i < numFrames; ++i)
{
  var textureName = string.Format("Frame{0:0000}", i);
  Debug.Log(textureName);
}