Hi
I have been trying to figure out how to change the texture of the cube dymically
this is the script that i have used. It changes the texture only once
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
public float updateInterval = 0.5F;
private float accum = 0; // FPS accumulated over the interval
private int frames = 0; // Frames drawn over the interval
private float timeleft;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
timeleft -= Time.deltaTime;
accum += Time.timeScale/Time.deltaTime;
++frames;
// Interval ended - update GUI text and start new interval
if( timeleft
{
// display two fractional digits (f2 format)
float fps = accum/frames;
string format = System.String.Format("{0:F2} FPS",fps);
guiText.text = format;
if(fps
{
Texture2D tex = Resources.Load("5") as Texture2D;
GameObject.Find("Cube").renderer.material.mainTexture= tex;
}
else
{
Texture2D tex = Resources.Load("1") as Texture2D;
GameObject.Find("Cube").renderer.material.mainTexture= tex;
}
// DebugConsole.Log(format,level);
timeleft = updateInterval;
accum = 0.0F;
frames = 0;
}
}
}
I think update function is been called only once
Ah, I just read the title of your post again. Your code won't change the texture every three seconds, instead it changes the texture when the framerate changes. Try reworking the code a bit, if you use updateInterval = 3.0f you should be able to toggle the texture directly in your if statement (don't check against the fps).
- Kim