- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
cubictoast · Oct 03, 2013 at 12:40 AM ·
fpsdistancemeleecombat
Distance will not calculate after button is pressed
Below is a basic melee script, where once the left mouse button is pressed, it is supposed to calculate the distance between myself and an object on screen, however, when the left mosue button is pressed, nothing is calculated. This is vital to determine whether or not a melee hit is close enough to register against the opponent. Is there a reason why this is not working? Also, I am a complete novice when it comes to scripting in general, so if you will, please simplify any answers you give.
the Melee Script:
pragma strict
var TheDammage : int = 50;
var Distance : float;
var MaxDistance : float = 1.5;
var TheSystem : Transform;
function Update ()
{
if (Input.GetButtonDown("Fire1"))
{
}
// if (TheMace.animation.isPlaying == false)
// {
// TheMace.animation.CrossFade("Idle");
// }
//
// if (Input.GetKey (KeyCode.LeftShift))
// {
// TheMace.animation.CrossFade("Sprint");
// }
//
// if (Input.GetKeyUp(KeyCode.LeftShift))
// {
// TheMace.animation.CrossFade("Idle");
// }
}
function AttackDammage ()
{
//Attack function
var hit : RaycastHit;
if (Physics.Raycast (TheSystem.transform.position, TheSystem.transform.TransformDirection(Vector3.forward), hit))
{
Distance = hit.distance;
if (Distance < MaxDistance)
{
hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613115214im_/https://answers.unity.com/themes/thub/images/avi.jpg)