Hey guys, I’m new to Unity so any help would be much appreciated. I wrote a Java script for my character to attack, but when I play it, the weapon automatically attacks repeatedly without even clicking!
Here’s the script:
#pragma strict
var TheDamage : int = 50;
var Distance : float;
var MaxDistance : float = 1.5;
var TheMace : Transform;
function Update ()
{
if (Input.GetButtonDown("Fire1"));
{
TheMace.animation.Play("Attack 1");
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit));
{
Distance = hit.distance;
if (Distance < MaxDistance);
(
hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver)
);
}
}
}
Here’s the script for the enemy:
#pragma strict
var Health = 100;
function Update ()
{
if(Health <= 0)
{
Dead();
}
};
function ApplyDamage (TheDamage : int)
{
Health -= TheDamage;
};
function Dead()
{
Destroy (gameObject);
}
Thanks!