Quantcast
Channel: Questions in topic: "gun"
Viewing all articles
Browse latest Browse all 592

Controlled Automatic Fire Rate (RayCasting)

$
0
0
Hey guys. I am having some problems with an automatic but controlled ray cast firing system. It goes as followed; if (Input.GetButton("Fire1") && aiming && canShoot && !shooting && currentClip >= 1 && !reloading && m9showing && Time.time > nextFire) { Shooting.shooting(); currentClip -= 1; shooting = true; canShoot = false; animation.Play("Z_Multiple_Shot"); } if(Input.GetButton("Fire1") && walking && !aiming && m9showing && Time.time > nextFire || Input.GetButton("Fire1") && idle && !aiming && currentClip >= 1 && !reloading && m9showing && Time.time > nextFire) { Shooting.shooting(); currentClip -= 1; shooting = true; canShoot = false; animation.Play("Multiple_Shot"); } //----------------------------------------------------------------------------------------------------------\\ #pragma strict var bulletHole : GameObject; var TheDammage : int = 100; function Update() { Debug.DrawRay (transform.position, Vector3.forward * 10, Color.green); } function shooting () { var hit : RaycastHit; for(var i : int = 0; i < 10; i++) { if(Physics.Raycast(transform.position, transform.forward, hit,100.0)) { var hitRotation = Quaternion.FromToRotation(Vector2.up, hit.normal); if(hit.transform.tag == "Wall") { Instantiate(bulletHole, hit.point, hitRotation); } hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver); Debug.Log( " Ray Hit " + hit.collider.gameObject.name); } yield WaitForSeconds(.08); } } I understand that when `if(Input.GetButton("Fire1"))` where as `if(Input.GetButtonDown("Fire1"))` will only fire once per click. On another note my `shooting();` class is connected to another game object but I know I am accessing the script's class correctly. I was thinking a timer but I could't figure out how to imply it. Does ray casting itself have a function that will control how much or fast it will ray cast? Anyways I need to slow down the fire rate using a timer but I don't know how to do this. Thanks in advance!

Viewing all articles
Browse latest Browse all 592

Trending Articles



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