I want to create a button bash, for example clicking the Left Mouse 8 times in a period of time, to play an animation. Does anyone can give me a simple example of this in JavaScript?
Here is one way that should work, you will need to have the animation object attached to the same object as the script and make sure “animName” matches that animation objects name. Borrowed the basic idea from a gun firing delay script somewhere.
//These go after class definition
var clicksRequired: Int = 8; //how many clicks you need
var clicksPerTime: Int; //how many are currently active
var clickLife: Int = 1; //how long you get
var nextClickFade: Float; //how long till oldest active click is subtracted
//This goes in update
if(Input.GetMouseButtonDown(0))
{
//Add current click
clicksRequired ++;
//Check whether you have reached the goal rate and activate reward anim
if(clicksPerTime >= clicksRequired)
{
animation.Play("animName");
}
}
//Check if oldest click has reached fade time
if(Time.time > nextFire)
{
//Subtract oldest click
clicksRequired --;
//Set delay before next oldest click is subtracted
nextClickFade = Time.time + clickLife;
}