Hi!
What I want to archieve:
I would like to have the button pressed for a period of time to open a chest box for instance.
Like - hold down the button for 3 second → open chest box. When button released is released before 3, reset the timer and do nothing. When pressed and hold, count again…
I am using a simple script to get a button event while the mouse button is pressed like this:
using UnityEngine;
using System.Collections;
public class charge_hit : MonoBehaviour {
public float chargeMove;
public float chargeMoveTimer = 1;
// Update is called once per frame
void Update () {
if (Input.GetButton("Fire1") )
{
chargeMoveTimer+=Time.deltaTime;
}
if ((Input.GetButton("Fire1")) && (chargeMoveTimer>5))
{
print("Open Something!");
}
if ((Input.GetButton("Fire1")) && (chargeMoveTimer<5))
{
print("Not Open!");
}
}
}
How coud I archieve to get ChargeMoveTimer reset after the button is not pressed any longer,
so the counter restarts the next time I press the button.
Thanks!