Hi! When i press Mousebutton1 i want to call attack one time and then wait like 2 sec until it can be called again (this way spamming mousebutton1 wont be possible) but i cant figure out how to do this. Can you help me?
The code is in JS
#pragma strict
var TheDamage : int = 25;
private var Distance : float;
var MaxDistance : float = 1.5;
var TheAnimator : Animator;
var DamageDelay : float = 0.6;
var Wait : boolean = false;
private var Hit01Streak = 0;
private var Hit02Streak = 0;
function Update ()
{
if (Input.GetButtonDown(“Fire1”))
{
Wait = true;
AttackDamage();
}
}
function AttackDamage ()
{
if (Random.value >= 0.5 && Hit01Streak <= 2)
{
TheAnimator.SetBool(“Hit01”, true);
Hit01Streak += 1;
Hit02Streak = 0;
}
else
{
if (Hit02Streak <= 2)
{
TheAnimator.SetBool(“Hit02”, true);
Hit01Streak = 0;
Hit02Streak += 1;
}
else
{
TheAnimator.SetBool(“Hit01”, true);
Hit01Streak += 1;
Hit02Streak = 0;
}
}
yield WaitForSeconds(DamageDelay);
//Actual attacking
Wait = false;
var hit : RaycastHit;
var ray = Camera.main.ScreenPointToRay(Vector3(Screen.width/2, Screen.height/2, 0));
if (Physics.Raycast (ray, hit))
{
Distance = hit.distance;
if (Distance < MaxDistance)
{
hit.transform.SendMessage(“ApplyDamageEnemy”, TheDamage, SendMessageOptions.DontRequireReceiver);
Debug.Log(“The Player Has Attacked”);
}
}
TheAnimator.SetBool(“Hit01”, false);
TheAnimator.SetBool(“Hit02”, false);
}