Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

shooting script wont damage enemy

$
0
0
i am making a zombie survival game and i ran into a problem that is when i shoot my gun using raycast at my enemy its should kill him but it does no damage until he is almost 2 feet away. shooting script: #pragma strict var damage : int = 100; var meleeaim : Transform; var ammo = 15; var clips = 10; function Update() { if (Input.GetKey(KeyCode.LeftShift)) { animation.CrossFade("walking"); } if (Input.GetButtonDown("Fire1") && ammo >= 1) { // animation.Play("shoot"); attackdamage(); } if (ammo <= 0 && clips >= 1) { reload(); } if (animation.isPlaying == false) { animation.CrossFade("gunidel"); } // if (Input.GetKey(KeyCode.LeftShift)) { // animation.CrossFade("swordrun"); // } if (Input.GetKeyUp(KeyCode.LeftShift)) { animation.CrossFade("gunidel"); } } function attackdamage() { var hit : RaycastHit; if (Physics.Raycast(meleeaim.transform.position, meleeaim.transform.TransformDirection(Vector3.forward), hit)) { hit.transform.SendMessage("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver); } } function shoot() { ammo -= 1; } function reload() { clips -= 1; ammo = 10; } enemy health: #pragma strict var damage : int = 100; var meleeaim : Transform; var ammo = 15; var clips = 10; function Update() { if (Input.GetKey(KeyCode.LeftShift)) { animation.CrossFade("walking"); } if (Input.GetButtonDown("Fire1") && ammo >= 1) { // animation.Play("shoot"); attackdamage(); } if (ammo <= 0 && clips >= 1) { reload(); } if (animation.isPlaying == false) { animation.CrossFade("gunidel"); } // if (Input.GetKey(KeyCode.LeftShift)) { // animation.CrossFade("swordrun"); // } if (Input.GetKeyUp(KeyCode.LeftShift)) { animation.CrossFade("gunidel"); } } function attackdamage() { var hit : RaycastHit; if (Physics.Raycast(meleeaim.transform.position, meleeaim.transform.TransformDirection(Vector3.forward), hit)) { hit.transform.SendMessage("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver); } } function shoot() { ammo -= 1; } function reload() { clips -= 1; ammo = 10; } does anyone know how to fix this. ---------- ---------

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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