Can someone please fix this code.
Im new to Unity and i tried everything and i cant fix this code.
I get unknown indentifier error.
#pragma strict
var Bullet :GameObject;
var Ammo : int = 30;
var FirePoint :GameObject;
var FireMode : String = "Semi" ;
function Start () {
}
function Update ()
{
if(FireMode == "Semi");
}
{
if(Input.GetMouseButton(0))
{
FireOneBullet () ;
}
}
function FireOneBullet(){
Instantiate(bullet, firePoint.transform.position,firePoint.transform.rotation);
ammo -- ;
Ammo--;
}
When posting compiling problems, please include the the error message copied from the console.
There are a few problems in this code. First pay very close attention to your indentation and how you balance your opening and closing. For example you have an extra closing bracket on line 15 that is not matched by an open bracket.
Some other issues:
- Line 14 has a unwanted ‘;’ at the end
- Case matters. so ‘bullet’ is not the same ‘Bullet’. By convention, variable names should start lower case. You have several places where the declaration and the use don’t match in case.
- Line 31 needs to be removed.
Here is your code with corrections so that it compiles:
#pragma strict
var bullet :GameObject;
var ammo : int = 30;
var firePoint :GameObject;
var fireMode : String = "Semi" ;
function Start () {
}
function Update ()
{
if (fireMode == "Semi")
{
if(Input.GetMouseButton(0))
{
FireOneBullet () ;
}
}
}
function FireOneBullet() {
Instantiate(bullet, firePoint.transform.position,firePoint.transform.rotation);
ammo--;
}