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

My gun reloading dont work,can i please get help.

$
0
0
using System.Collections; using System.Collections.Generic; using UnityEngine; public class shoot : MonoBehaviour { public Rigidbody bulletPrefab; public Transform bulletSpawn; public float shootingSpeed; public int bulletAmmount; int shootedBulletAmmount; public int currentBulletAmmount; bool isSpawned; bool canShoot; void Start() { canShoot = true; } void Update() { Shoot (); Reload (); } void Shoot () { if(canShoot==true) { if (Input.GetButtonDown ("Fire1")) { shootedBulletAmmount = shootedBulletAmmount++; isSpawned = true; print (shootedBulletAmmount); Rigidbody rocketInstance; rocketInstance = Instantiate (bulletPrefab, bulletSpawn.position, bulletSpawn.rotation) as Rigidbody; rocketInstance.AddForce (bulletSpawn.forward * shootingSpeed); } } } void Reload() { if(isSpawned==true) { currentBulletAmmount = bulletAmmount -= shootedBulletAmmount; } if (currentBulletAmmount <= 0) { canShoot = false; } if (canShoot == false) { StartCoroutine("readyShoot"); } } IEnumerator readyShoot() { yield return new WaitForSeconds (3); canShoot = true; bulletAmmount = 20; shootedBulletAmmount = 0; currentBulletAmmount = 0; } }

Viewing all articles
Browse latest Browse all 592

Trending Articles



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