- Home /
Question by
MineReaps · Nov 19, 2014 at 03:24 AM ·
javascriptdistancedamage
My weapon does no damage?
I have been watching brackeys tutorial on how to make a survival game and it seems like i have messed up the weapon. It does no damage even tough the script is downloaded direcly from his web. I belive that it has to do something with the unity settings but i just cant figure it out.
var TheDammage : int = 50;
var Distance : float;
var MaxDistance : float = 1.5;
var TheSystem : Transform;
function Update ()
{
if (Input.GetButtonDown("Fire1"))
{
animation.Play("Attack");
}
}
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);
}
}
}
Everything works perfecly except this, and i think it has something to do with the var Distance : float;
The Distance value should change each time i attack but it does not. Here is an video of his video for a greater understanding of my problem https://www.youtube.com/watch?v=C6c9J9CSEvA Thank you in advance.
Comment
Please correctly format code when posting. Highlight all code and click the 101/010 button.
Your answer
![](https://koobas.hobune.stream/wayback/20220613171855im_/https://answers.unity.com/themes/thub/images/avi.jpg)