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

musket gun script is not working

$
0
0
this script is supposed to make the gun shoot once and then reload but it just lets me keep shooting i am pretty much a beginner with scripting here is the script var reloadTime = 5; var totalAmmo = 10; var ammoCount = 1; function Update () { if (ammoCount >= 1) { CanShoot = true; } if (ammoCount <= 0) { CanShoot = false; } if (CanShoot == false) { reload(); } if (CanShoot == true) { Shoot(); } } function Shoot () { var hit : RaycastHit; var ray: Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0)); if (Input.GetMouseButtonDown(0)) { if (Physics.Raycast (ray, hit, 100)) { hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver); {ammoCount -= 1; } } } } function reload () { if (Input.GetKeyDown("r")) { yield WaitForSeconds(reloadTime); //waits for "reloadTime" before adding ammo ammoCount += 1; //adds ammo to our "clip" based off the reloadAmount totalAmmo -= 1; //subtracts whatever the reloadAmount was from our total ammo every time we reload } }

Viewing all articles
Browse latest Browse all 592


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