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

Wrote a script for Shooting, reloading and to display the AMMO in a GUIText

$
0
0
This is the script, When ever I start the game It says "Assets/shoot.js(17,22): BCE0018: The name 'ammotext' does not denote a valid type('not found')" I have no Idea what to do >.> var sound : AudioClip; //ie_shot_gun-liminalace-770179786 soundClip var reloadSound: AudioClip; //reload soundClip var BulletSpeed = 100; //force of bullets being shot var projectile : Rigidbody; //bullet prefab goes here var bullets = 30; //amount of bullets per "clip" var totalBullets = 60; //total amount of bullets we have available var reloadTime = 3; //time to reload var reloadAmount = 10; var ammo : ammotext; //GUI text for our bullet/ammo count function Update () { Fire (); Reload (); } function Fire () { if(bullets > 0) { //if we have at least 1 bullet then we can fire if (Input.GetButtonDown("Fire1")) { var clone : Rigidbody;// Instantiate the projectile at the position and rotation of this transform clone = Instantiate(projectile, transform.position, transform.rotation); clone.velocity = transform.TransformDirection (Vector3.forward * BulletSpeed);// Give the cloned object an initial velocity along the current AudioSource.PlayClipAtPoint(sound, transform.position, 1); // object's Z axis bullets -=1; //subtracts one bullet per fire sequence } } } function Reload () { if(bullets < 1) { //if we have less than 1 bullet then we can reload if(Input.GetKeyDown("r")) { AudioSource.PlayClipAtPoint(reloadSound, transform.position, 1); //plays reload soundclip yield WaitForSeconds(reloadTime); //waits for "reloadTime" before adding bullets bullets += reloadAmount; //adds 3 bullets to our "clip" totalBullets -= reloadAmount; //subtracts 3 bullets from our totalBullets amount } } } function OnGUI () { ammo.text = "bullets: " + bullets + "/" + totalBullets.ToString(); }

Viewing all articles
Browse latest Browse all 592

Trending Articles



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