Hello i made a code for gun shooting with sound and i get a lot of errors can somebody help me?
I get this errors: -----Assets/Scripts/GunShoot.js(2,31): UCE0001: ‘;’ expected. Insert a semicolon at the end.-------
---- Assets/Scripts/GunShoot.js(3,15): UCE0001: ‘;’ expected. Insert a semicolon at the end.-----
---- Assets/Scripts/GunShoot.js(13,8): BCE0043: Unexpected token: if.-----
-----Assets/Scripts/GunShoot.js(14,15): BCE0044: expecting :, found ‘;’.------
Code:::::
public var BulletPrefab : Transform;
public var BulletSpeed : float 5000;
var Ammo : int 30;
var GunShoot : AudioClip;
var Reload : AudioClip;
var EmptyClip : boolean = false;
function Update(){
if(Input.GetButtonDown("Fire1"));{
if(Ammo > 0);{
Shoot();
}
else(){
return;
}
}
if(Input.GetButtonDown(KeyCode.R));{
if(EmptyClip){
Reload();
}
}
if(Ammo >= 0){
EmptyClip = true;
}
else{
EmptyClip = false;
}
}
function Shoot()
{
var Bullet = Instantiate(BulletPrefab, transform.Find("Spawn")).position, transform.Find("Spawn").rotation);
Bullet.rigidbody.AddForce(transform.foward *BulletSpeed);
Audio.PlayOneShoot(M4A3Shoot);
Ammo--;
}
function Reload()
{
Audio.PlayOneShoot(gun_reload_1);
Ammo = 30;
}
function OnGui()
{
GUI.Label(Rect(0, 0, 75, 23)"Ammo" +Ammo);
}
Don't post answers to your own question, with even more questions. Just update your first one with your current problem. (And go and delete those other answers.) Also, clean out your script. People will only help you, if the code is readable. Now it just looks like you copied it from a site somewhere.
Don’t put semi-colons between if statements and their curly braces. You’re doing:
if(true);
{
// do things
}
when you should be doing:
if(true)
{
// do things
}
Sorry, I didn't keep looking after i saw that. Take note anyway. By putting a semi colon before the curly braces you're basically saying "if this condition is true, do nothing. Then, always do whatever is in these curly braces."
ok so i fixed that but now i get even more errors:
Assets/Scripts/GunShoot.js(2,31): UCE0001: ‘;’ expected. Insert a semicolon at the end.
Assets/Scripts/GunShoot.js(3,15): UCE0001: ‘;’ expected. Insert a semicolon at the end.
Assets/Scripts/GunShoot.js(16,12): BCE0043: Unexpected token: (.
Assets/Scripts/GunShoot.js(17,8): BCE0043: Unexpected token: return.
Assets/Scripts/GunShoot.js(31,1): BCE0044: expecting EOF, found ‘}’.
code:
public var BulletPrefab : Transform;
public var BulletSpeed : float 5000;
var Ammo : int 30;
var GunShoot : AudioClip;
var Reload : AudioClip;
var EmptyClip : boolean = false;
Line 8: should be else{, not else(){. Line 32, should be transform.forward, not foward(use the autocomplete whenever you can). Line 54: add a comma between the Rect definition and the “Ammo”. Can’t see anything else, see if that did it.
Don't post answers to your own question, with even more questions. Just update your first one with your current problem. (And go and delete those other answers.) Also, clean out your script. People will only help you, if the code is readable. Now it just looks like you copied it from a site somewhere.
– Unitraxx