so I have the most strange script ever made.
it works like a charm
but when clip is 1 or 2 and totalbullets is 16 the script won’t work it’s soooo strange can someone tell me what might be the problem
here’s the script
var ReloadTime = 1;
var Nifes = 3;
var SpreadFactor : float = 0;
var AimSpread : float = 0.01;
var HipFireSpread : float = 0.01;
var AimCamera : GameObject;
var BulletHole : GameObject;
var Nife : GameObject;
var NifeSpawn : GameObject;
var IsReloading = false;
var GunFireSound : AudioClip;
var EmptyGunSound : AudioClip;
var Gun : GameObject;
var GunReloadSound : AudioClip;
var AnimationPlayed = false;
var MuzzleFlash : Renderer;
function Start() {
GunReloadAnimation = Gun.GetComponent.<Animator>();
MuzzleFlash.enabled = false;
}
function Update() {
AimCamera.GetComponent.<Crosshair>().enabled = true;
SpreadFactor = HipFireSpread;
if(Input.GetButton("Fire2")){
AimCamera.GetComponent.<Crosshair>().enabled = false;
SpreadFactor = AimSpread;
}
if(Input.GetButton("Fire1") && Time.time > NextFire && Clip > 0){
NextFire = Time.time + FireRate;
GetComponent.<AudioSource>().clip = GunFireSound;
GetComponent.<AudioSource>().time = 0.2f;
GetComponent.<AudioSource>().Play();
Rayshooting();
Clip --;
}
else if(Clip == 0 && TotalBullets != 0){
GetComponent.<AudioSource>().time = 0.4f;
GetComponent.<AudioSource>().clip = GunReloadSound;
GetComponent.<AudioSource>().Play();
Reload();
}
else if(Input.GetButtonDown("Fire1") && Clip == 0 && TotalBullets == 0){
EmptySound();
}
if(Input.GetKey(KeyCode.R) && Clip < 30 && TotalBullets != 0 && IsReloading == false) {
GetComponent.<AudioSource>().time = 0.4f;
GetComponent.<AudioSource>().clip = GunReloadSound;
GetComponent.<AudioSource>().Play();
Reload();
}
if(Input.GetKeyDown(KeyCode.E) && Nifes > 0){
Instantiate(Nife, NifeSpawn.transform.position, NifeSpawn.transform.rotation);
Nifes --;
}
}
function Rayshooting() {
{
MuzzleFlash.GetComponent.<Renderer>().enabled = true;
yield WaitForSeconds(0.02);
MuzzleFlash.GetComponent.<Renderer>().enabled = false;
}
var direction : Vector3 = transform.forward;
direction.x += Random.Range(-SpreadFactor, SpreadFactor);
direction.y += Random.Range(-SpreadFactor, SpreadFactor);
direction.z += Random.Range(-SpreadFactor, SpreadFactor);
Debug.DrawRay(transform.position,direction * BulletRange);
var hit : RaycastHit;
bHit = Physics.Raycast(transform.position,direction,hit,BulletRange);
if (bHit && hit.transform.gameObject.tag == "Enemy"){
hit.transform.SendMessage("DamageTaken", Damage, SendMessageOptions.DontRequireReceiver);
}
else if (bHit && hit.transform.gameObject.tag == "Buildings" || "Buildings2"){
var CloneHole = Instantiate(BulletHole, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(CloneHole, 5);
}
}
function Reload() {
if(Clip == 0 && TotalBullets >= 30){
Clip = 30;
TotalBullets -= 30;
Debug.Log("Did reload 1");
}
if(Clip == 0 && TotalBullets << 30){
Clip = TotalBullets;
TotalBullets = TotalBullets - TotalBullets;
Debug.Log("Did reload 2");
}
if(Clip != 0 && TotalBullets >= 30 - Clip){
TotalBullets = TotalBullets - (30 - Clip);
Clip = 30;
Debug.Log("Did reload 3");
}
else if(Clip != 0 && TotalBullets << 30 - Clip){
Clip = Clip + TotalBullets;
TotalBullets = 0;
Debug.Log("Did reload 4");
}
}
function EmptySound(){
GetComponent.<AudioSource>().time = 0.0f;
GetComponent.<AudioSource>().volume = 1;
GetComponent.<AudioSource>().clip = EmptyGunSound;
GetComponent.<AudioSource>().Play();
}