- Home /
hey guys texture switch script for an texture animation
hey guys im looking for a script some guys are talking aboute thay say thare is a script that allows you to put more textures on a model and yoy can play tham a a animation on the object
if possible please ad a frame per second time(); so i can tweak the frame rate when i wanted to thanks by the way
A place to start in making a texture switching script is: http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$aterial.GetTexture.html and http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$aterial.SetTexture.html. I'm not very experienced and am currently learning these things myself.
This is a forum for people looking for help with bugs, not a place to get free scripts. Try the Unify Wiki.
Answer by anwserman · Jul 26, 2012 at 10:42 PM
This should be incredibly simple to do. I'll tell you how to do it, but you can code it yourself.
Create a script with these public variables:
Array of a material datatype
Starting Frame as float
Frames per second as float
You'll also want a private variable:
Current frame as float
During the script's start, put this in it:
CurrentFrame = StartingFrame
During the Update, this is the code you'll want to put into it
CurrentFrame += (Time.deltaTime * FramesPerSecond)
rem error checking code so we can play animation forwards (positive fps)
if (int(currentFrame) > MaterialArray.Count)
currentFrame = currentFrame - MaterialArray.Count
rem error checking code so we can play animation backwards (negative fps)
if (int(currentFrame) < 0)
currentFrame += MaterialArray.Count
rem apply the material to the gameobject
GameObject.ApplyMaterial(MaterialArray[int(currentFrame)])
This is all pseudocode, but it'll work once you get it properly tailored towards the Unity workspace. I haven't done this specifically in Unity, but this is how I always programmed my animations in my 2D projects and 3D projects in other engines.
.
Your answer

Follow this Question
Related Questions
Animated Rotten Tomato 0 Answers
Double Layer Material 0 Answers
Animating from texture to texture 1 Answer
Infintely scrolling texture ends?(only scrolls through once) 1 Answer
3D Mesh Deformer in Unity3D 2 Answers