I’m work in JavaScript I make movement button in NGUI so I need repeat button according to my search I found this,
public class RepeatButtons : MonoBehaviour
{
public float delay = 1.00f;
public float interval = 0.25f;
bool mIsPressed = false;
float mNextClick = 0f;
void OnPress (bool isPressed)
{
mIsPressed = isPressed;
mNextClick = Time.realtimeSinceStartup + delay;
// Perform action as soon as button is pressed.
if (isPressed)
PerformAction();
}
void Update ()
{
// Adjusted condition slightly...
if (mIsPressed && Time.realtimeSinceStartup >= mNextClick)
{
mNextClick = Time.realtimeSinceStartup + interval;
PerformAction();
}
}
void PerformAction() {
//Do something
}
}
I try to something but it is not working.
public var delay : float = 1.00f;
public var interval : float = 0.25f;
var mIsPressed : boolean = false;
var mNextClick : float = 0f;
var isPressed : boolean = true;
function OnPress ()
{
mIsPressed = isPressed;
mNextClick = Time.realtimeSinceStartup + delay;
// Perform action as soon as button is pressed.
if(isPressed){
PerformAction();
}
}
function Update ()
{
// Adjusted condition slightly...
if(mIsPressed && Time.realtimeSinceStartup >= mNextClick)
{
mNextClick = Time.realtimeSinceStartup + interval;
PerformAction();
}
}
function PerformAction() {
Debug.Log("Hey ho");
}
How I convert this to JS?