- Home /
1 script doesn't react to input
so I have a shooting script which did work at first and then I went off for a while and came back to unity to start working on the project again and suddenly only this script doesn't react to my mouse input anymore
gun won't shoot and I can reload and all that kind of stuff that's in the script does anyone know what's wrong also there are no error messages at all
here is the script
var Damage = 10;
var FireRate = 0.1F;
var NextFire = 0.0F;
var BulletRange = 200;
var ClipAk = 30;
var TotalBulletsAk = 90;
var ClipUMP = 45;
var TotalBulletsUMP = 135;
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 : GameObject;
var GunTwo : GameObject;
var ActiveGun = 2;
var GotGunTwo = false;
function Start() {
GunReloadAnimation = Gun.GetComponent.<Animator>();
}
function Update() {
MuzzleFlash = gameObject.FindWithTag("MuzzleFlash");
MuzzleFlash.GetComponent.<Renderer>().enabled = false;
AimCamera.GetComponent.<Crosshair>().enabled = true;
SpreadFactor = HipFireSpread;
if(Input.GetButton("Fire2")){
AimCamera.GetComponent.<Crosshair>().enabled = false;
SpreadFactor = AimSpread;
}
}
if(ActiveGun == 1){
if(Input.GetButton("Fire1") && Time.time > NextFire && ClipAk > 0){
NextFire = Time.time + FireRate;
GetComponent.<AudioSource>().clip = GunFireSound;
GetComponent.<AudioSource>().time = 0.2f;
GetComponent.<AudioSource>().Play();
Rayshooting();
ClipAk --;
}
else if(ClipAk == 0 && TotalBulletsAk != 0){
GetComponent.<AudioSource>().time = 0.4f;
GetComponent.<AudioSource>().clip = GunReloadSound;
GetComponent.<AudioSource>().Play();
ReloadAk();
}
else if(Input.GetButtonDown("Fire1") && ClipAk == 0 && TotalBulletsAk == 0){
EmptySound();
}
if(Input.GetKey(KeyCode.R) && ClipAk < 30 && TotalBulletsAk != 0 && IsReloading == false) {
GetComponent.<AudioSource>().time = 0.4f;
GetComponent.<AudioSource>().clip = GunReloadSound;
GetComponent.<AudioSource>().Play();
ReloadAk();
}
}
if(ActiveGun == 2){
if(Input.GetButton("Fire1") && Time.time > NextFire && ClipUMP > 0){
NextFire = Time.time + FireRate;
GetComponent.<AudioSource>().clip = GunFireSound;
GetComponent.<AudioSource>().time = 0.2f;
GetComponent.<AudioSource>().Play();
Rayshooting();
ClipUMP --;
}
else if(ClipUMP == 0 && TotalBulletsUMP != 0){
GetComponent.<AudioSource>().time = 0.4f;
GetComponent.<AudioSource>().clip = GunReloadSound;
GetComponent.<AudioSource>().Play();
ReloadUMP();
}
else if(Input.GetButtonDown("Fire1") && ClipUMP == 0 && TotalBulletsUMP == 0){
EmptySound();
}
if(Input.GetKey(KeyCode.R) && ClipUMP < 45 && TotalBulletsUMP != 0 && IsReloading == false) {
GetComponent.<AudioSource>().time = 0.4f;
GetComponent.<AudioSource>().clip = GunReloadSound;
GetComponent.<AudioSource>().Play();
ReloadUMP();
}
}
if(Input.GetKeyDown(KeyCode.E) && Nifes > 0){
Instantiate(Nife, NifeSpawn.transform.position, NifeSpawn.transform.rotation);
Nifes --;
}
if(GotGunTwo == true){
if(Input.GetKeyDown(KeyCode.Alpha1)){
WeaponSwitch();
}
}
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 ReloadAk() {
if(ActiveGun == 1){
Gun.GetComponent.<Animation>().Play("Reload");
}
else if(ActiveGun == 2){
GunTwo.GetComponent.<Animation>().Play("Reload UMP");
}
yield WaitForSeconds(ReloadTime);
if(ClipAk < 30 && TotalBulletsAk > 0){
var refill = Mathf.Min(30 - ClipAk, TotalBulletsAk);
TotalBulletsAk -= refill;
ClipAk += refill;
}
}
function ReloadUMP() {
if(ActiveGun == 1){
Gun.GetComponent.<Animation>().Play("Reload");
}
else if(ActiveGun == 2){
GunTwo.GetComponent.<Animation>().Play("Reload UMP");
}
yield WaitForSeconds(ReloadTime);
if(ClipUMP < 45 && TotalBulletsUMP > 0){
var refill = Mathf.Min(45 - ClipUMP, TotalBulletsUMP);
TotalBulletsUMP -= refill;
ClipUMP += refill;
}
}
function EmptySound(){
GetComponent.<AudioSource>().time = 0.0f;
GetComponent.<AudioSource>().volume = 1;
GetComponent.<AudioSource>().clip = EmptyGunSound;
GetComponent.<AudioSource>().Play();
}
function WeaponSwitch(){
if(Gun.active == true){
Gun.GetComponent.<Animation>().Play("WeaponOut");
yield WaitForSeconds(0.5);
Gun.SetActive(false);
GunTwo.SetActive(true);
GunTwo.GetComponent.<Animation>().Play("WeaponIn");
ActiveGun = 2;
}
else{
GunTwo.GetComponent.<Animation>().Play("WeaponOut");
yield WaitForSeconds(0.5);
GunTwo.SetActive(false);
Gun.SetActive(true);
Gun.GetComponent.<Animation>().Play("WeaponIn");
ActiveGun = 1;
}
}
Answer by Landern · Aug 25, 2016 at 08:32 PM
Line 46, you close the Update function with a closing curly brace. This kills your input if statements. You should remove the closing curly brace on that line and check all of your code blocks.
Your answer
Follow this Question
Related Questions
reload script does not work when ammo is 16 2 Answers
Help with reloading gun. 1 Answer
How can I shoot bullets that you can aim with the crosshair? 1 Answer
GetButtonDown problem | C# 0 Answers
Control amount of bullets 2 Answers