Hello
I have a GUIText and I want it to say 1%, then 2%, then 3%, etc. Every 1.2 seconds until it hits 100%. How would I do this?
This is just a small example to give you an idea:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace rkk.unity.experimental
{
private int onePointTwoSecCounter = 0;
private float optscNextUpdate = 1.2f;
private float optscLastUpdate = 0.0f;
public class rkkExperimental1 : MonoBehaviour
{
void Update ()
{
optscLastUpdate = optscLastUpdate + (Time.deltaTime * Time.timeScale);
if (optscLastUpdate >= optscNextUpdate)
{
onePointTwoSecCounter++;
optscNextUpdate = optscNextUpdate + 1.2f;
if (onePointTwoSecCounter >= 100)
{
optscNextUpdate = optscNextUpdate + 10000000000.0f;
}
}
UpdateGUIText();
} //<- void Update ()
void OnGUI()
{;
UpdateGUIText();
} //<- void OnGUI ()
void UpdateGUIText()
{
guiText.text = string.Format("{0}%", onePointTwoSecCounter);
} //<- void UpdateGUIText()
}
}
I’m sorry but I don’t know C# very well. Is there any way you could give some sort of link or something so I could see it in jacascript? Maybe in the unity docs
I’m not that much of a JS guy, but it should looks like:
#pragma strict
// Ignore the 2 namespace warnings: http://forum.unity3d.com/threads/how-can-i-do-warning-message-namespace-system-collections-is-never-used-bcw00.103287/
private var onePointTwoSecCounter : int = 0;
private var optscNextUpdate : float = 1.2;
private var optscLastUpdate : float = 0.0;
function Start ()
{
}
function Update ()
{
optscLastUpdate = optscLastUpdate + (Time.deltaTime * Time.timeScale);
if (optscLastUpdate >= optscNextUpdate)
{
onePointTwoSecCounter++;
optscNextUpdate = optscNextUpdate + 1.2;
if (onePointTwoSecCounter >= 100)
{
optscNextUpdate = optscNextUpdate + 10000000000.0f;
}
}
UpdateGUIText();
}
function OnGUI()
{
UpdateGUIText();
} //<- void OnGUI ()
function UpdateGUIText()
{
guiText.text = onePointTwoSecCounter + "%";
} //<- void UpdateGUIText()