TextureSwap Animator

From Unify Community Wiki
Revision as of 15:16, 5 September 2009 by PsychicParrot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

by PsychicParrot.

Description

Attach it to a GUITexture, feed it a bunch of materials and it will cycle through them. I don't recommend this method, since using a texture atlas is more memory efficient.. but it's fine for simple GUI animations or for getting things up and running quickly.

usage

Attach to GUITexture. Add materials using the editor (put them into the materials list) Watch as they cycle! If you need to adjust the speed, change the changeInterval declaration (here it is shown as 0.33f).

<csharp> using UnityEngine; using System.Collections;

public class autoTextureSwappingGUITexture : MonoBehaviour {

public Texture[] materials; public float changeInterval = 0.33f; public int startFrame = 0; private GUITexture myGUITexture;

// Use this for initialization void Start () {

startFrame=0;

// if you want to start the animation on a random frame, uncomment the line below: //startFrame=Random.Range(0,materials.Length);

myGUITexture=gameObject.guiTexture;

}

// Update is called once per frame void Update () {

// we want this material index now float index = startFrame + (Time.time / changeInterval);

// take a modulo with materials count so that animation repeats index = index % materials.Length;

// assign it to the GUITexture myGUITexture.texture=materials[(int)index];

}

} </csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox