Help me pleaase!!! Problems with shooting script and reload
Hello I have this script that I got and implement some things in it, the problem is when reload the gun bullets station eg in texture 30/60, then 30/30, then 30/0, there when I spend these 30 rounds, the to recharge there ficaa 30 / -30, please help me, help me very much!
var bulletTex : GameObject[];
var power : int = 10;
var fireRate : float = 0.5;
private var nextFire : float = 0.0;
var gunShot : AudioClip;
var bullets : int = 5;
var reloadSound: AudioClip; //reload soundClip
var Balas = 30; //amount of coconuts per "clip"
var totalBalas = 60; //total amount of coconuts we have available
var reloadTime = 3; //time to reload
var reloadAmount = 10;
var ammo : GUIText; //GUI text for our coconut/ammo count
function Update () {
Reload ();
Fire ();
}
function Fire () {
if(Balas > 0) { //if we have at least 1 coconut then we can fire
if(Input.GetButton("Fire1") && Time.time > nextFire) {
nextFire = Time.time + fireRate;
AudioSource.PlayClipAtPoint(gunShot, transform.position, 1);
ForceFire();
}
}
}
function ForceFire () {
var fwd = transform.TransformDirection(Vector3.forward); //casts our raycast in the forward direction
var hit : RaycastHit;
Debug.DrawRay(transform.position, fwd * 10, Color.green); //drays our raycast and gives it a green color and a length of 10 meters
if(Input.GetButton("Fire1") && Physics.Raycast(transform.position, fwd, hit, 10)){ //when we left click and our raycast hits something bullets--;
Instantiate(bulletTex[Random.Range(0,1)], hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal)); //then we'll instantiate a random bullet hole texture from our array and apply it where we click and adjust
if(hit.collider.gameObject.tag == "Inimigo"){ //hit.rigidbody.AddForceAtPosition( direction * 100 , hit.point); //hit.collider.gameObject.animation.Play("die"); hit.collider.gameObject.SendMessage("ApplyDamage", 25);
} // the position and rotation of textures to match the object being hit
if (hit.rigidbody !=null)
hit.rigidbody.AddForceAtPosition(fwd * power, hit.point); //applies a force to a rigidbody when we click on it. Multiples our forward raycast times our power variable at the position we click
}
Balas -=1;
} function Reload () {
if(Balas < 1) { //if we have less than 1 coconut 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 coconuts
Balas += reloadAmount; //adds 3 coconuts to our "clip"
totalBalas -= reloadAmount; //subtracts 3 coconuts from our totalCoconuts amount
if (totalBalas < 0) { totalBalas--;
}
}
}
}
function OnGUI () {
ammo.text = "Balas: " + Balas + "/" + totalBalas.ToString();
}
Your answer
Follow this Question
Related Questions
Problem with my Weapon Recharge script 0 Answers
Basic FPS help! 2 Answers
weapon Spread 0 Answers
FPS Gun Hold 0 Answers
Hitmarker still shows while reloading 0 Answers