Hello forum. I need some quidance on how to make a texture animation on a GameObject to run, every time a gui.button is pressed. Let me explain what I have done so far. I have the “Texture Swap Animator.js” script from WiKi, attached to a GameObject, which I call to run through another js script, that contains a GUI.Button.
The Texture Swap Animator script is modified so, it only runs once, without looping. I want to make the script run from start everytime I hit the GUI.Button. How can this be done? Need your help to make it work as it should.
Here is the codding of the “Texture Swap Animator.js”:
#pragma strict
var frames : Texture2D[];
var framesPerSecond = 10.0;
function Update ()
{
var index : int = Time.time * framesPerSecond;
if (index < frames.Length)
{
renderer.material.mainTexture = frames[index];
}
}
Here is the coding of the script with the GUI.Button that is calling the above script to function:
#pragma strict
var native_width : float = 480;
var native_height : float = 320;
var btnTexture1 : Texture;
var Cam1 : Camera;
var Cam1On : boolean = false;
function Start()
{
Cam1.enabled = false;
}
function Update()
{
if (!Cam1On)
{
Cam1.enabled = false;
}
else
{
Cam1.enabled = true;
}
}
function OnGUI ()
{
//set up scaling
var rx : float = Screen.width / native_width;
var ry : float = Screen.height / native_height;
GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (rx, ry, 1));
//now create your GUI normally, as if you were in your native resolution
//The GUI.matrix will scale everything automatically.
if (!btnTexture1)
{
Debug.LogError("Please assign a texture on the inspector");
return;
}
if(GUI.Button(Rect(230, 120, 40, 25), btnTexture1))
{
Cam1On = !Cam1On;
}
I need to mention that the GameObject with the attached “Texture Swap Animator.js” script is visible only when the “Cam1On=true”, by clicking that GUI.Button.
Could someone be kind enough to point me to the right direction on how to implement this functionality to my Unity project?
Thank you all in advance for your time reading this post. Waiting for your answers.