Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

how can i change this script into fully automatic firing.

$
0
0
hi my current raycast shoot script only shoots one bullet one click at a time. does anyone know how i can adapt this to fully automatic firing. many thanks and heres my script: #pragma strict var Range : float = 1000; var Force : float = 1000; var hitMark : GameObject; var texta : GUITexture; var four : Texture; var three : Texture; var two : Texture; var one : Texture; var zero : Texture; var five : Texture; var bullets : int = 5; var shootSound : AudioClip; function Start () { } function Update () { if(Input.GetKeyDown(KeyCode.R)){ bullets = 5; GameObject.Find("GUN").animation.Play("reload"); } if(bullets == 5){ texta.guiTexture.texture = five; } else if(bullets == 0){ GameObject.Find("GUN").animation.Play("reload"); bullets = 5; } else if(bullets == 4){ texta.guiTexture.texture = four; } else if(bullets == 3){ texta.guiTexture.texture = three; } else if(bullets == 2){ texta.guiTexture.texture = two; } else if(bullets == 1){ texta.guiTexture.texture = one; } var hit : RaycastHit; var direction : Vector3 = transform.TransformDirection(Vector3.forward); Debug.DrawRay(transform.position , direction * Range , Color.blue); if(Input.GetMouseButtonDown(0)){ audio.PlayOneShot(shootSound); bullets--; if(Physics.Raycast(transform.position , direction , hit, Range)){ var hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal); if(hit.collider.gameObject.tag == "zombie"){ //hit.rigidbody.AddForceAtPosition( direction * 100 , hit.point); //hit.collider.gameObject.animation.Play("die"); Instantiate(hitMark); hit.collider.gameObject.SendMessage("ApplyDamage", 25); } } } }

Viewing all articles
Browse latest Browse all 171066

Trending Articles



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