Quantcast
Channel: Questions in topic: "melee"
Viewing all articles
Browse latest Browse all 201

What is wrong with this melee system?

$
0
0
Hello, guys! I am following some tutorials on Unity and I can't seem to figure out what might be the problem with this melee system. I have a player and an enemy. Player script: #pragma strict var Damage : int = 50; var Distance : float; var MaxDistance : float = 1.5; var TheMace : Transform; function Update () { if(Input.GetButtonDown("Fire1")) { TheMace.animation.Play("Attack"); var hit : RaycastHit; if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), hit)) { Distance = hit.distance; if(Distance < MaxDistance) { hit.transform.SendMessage("Apply Damage", Damage, SendMessageOptions.DontRequireReceiver); } } } } Enemy script: #pragma strict var Health = 100; function ApplyDamage (Damage : int) { Health -= Damage; } function Update () { if (Health <=0) { Dead(); } } function Dead () { Destroy (gameObject); } The enemy doesn't die, what can I do?

Viewing all articles
Browse latest Browse all 201

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>