- Home /
My automatic gun don't work help!
My shoot script don't work at least not the automatic gun all my ammo disapers at ones please help me i really need this
My script:
pragma strict
var Effect : Transform; var TheDammage = 100; var shootSound : AudioClip; var ammo : int; var NoAmmoSound : AudioClip; var MaxAmmo : int = 13; var BulletHole : Transform; var FullAuto : boolean = false; var FireRate : float = 0.01; private var NextFire : float = 0.0;
function start () {
}
function Update () {
if (Input.GetKeyDown("x"))
{
if (FullAuto == true)
{
FullAuto = false;
}
else
{
FullAuto = true;
}
}
if (FullAuto == true)
{
if (Input.GetMouseButton(0)&& Time.time > NextFire)
{
NextFire = Time.time + FireRate;
AMMO();
Fire();
}
}
if (FullAuto == false)
{
if (Input.GetMouseButtonDown(0))
{
AMMO();
Fire();
}
}
if(ammo > MaxAmmo)
ammo = MaxAmmo;
}
function OnGUI() { //Shows how mush ammo you have. if(ammo > 0) { GUI.Label(Rect(20,15,25,25),ammo.ToString()); } if(ammo == 0) { GUI.Label(Rect(20,15,45,45),"No Ammo"); } }
function Fire() {
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
if (Physics.Raycast (ray, hit, 100))
{
if(ammo > 0)
{
var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(particleClone.gameObject, 5);
hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
}
}
FireSound();
if(ammo > 0)
{
if(hit.collider.tag == "Prop")
{
Instantiate(BulletHole,hit.point,Quaternion.FromToRotation(Vector3.forward,hit.normal));
}
}
} function FireSound() {
if(ammo < 1) { if (Input.GetMouseButtonDown(0)) audio.PlayOneShot(NoAmmoSound); }
if(ammo > 0)
{
if (Input.GetMouseButtonDown(0))
audio.PlayOneShot(shootSound);
}
}
function AMMO() { if (ammo > 0) { ammo --; } }
You should really revise your post. Grammar errors need to be fixed in the opening, and the code needs to be formatted better. I immediately lost interest and will thus, not be attempting to answer this, but rather tell you this so you can improve the post.
Your answer
Follow this Question
Related Questions
pick up ammo from specific gun? 1 Answer
VR Weapons. New to Unity and need help. 2 Answers
Stop checking for key input 1 Answer
reset delay bar and and ammo 0 Answers