This is my script:
#pragma strict
var maxAmmo = 20;
var curAmmo;
function Start () {
curAmmo = 20;
}
function Update () {
if (Input.GetMouseButtonDown(1)) {
animation.Play ("Aim");
}
if (Input.GetMouseButtonUp(1)) {
animation.Play ("UnAim") ;
}
if (Input.GetMouseButtonDown(0)) {
if (curAmmo > 0)
{
animation.Play ("GunShoot") ;
curAmmo =- maxAmmo;
}
else
{
if (curAmmo < 1)
{
animation.Play("Reload4");
curAmmo = curAmmo;
}
}
}
if (Input.GetKey(KeyCode.R))
{
animation.Play("Reload4");
curAmmo = maxAmmo;
}
}
These are my errors:
[6303-error+please+help.png|6303]
var curAmmo : int;
You have to declare what curAmmo is. In this case it can be hole numbers.
This has been answered for you already on another post, please close this one. You need to tell Unity that maxAmmo and curAmmo are int. Because you are using pragma strict.
#pragma strict
var maxAmmo : int = 20;
var curAmmo : int;
I’m not very familiar with Unity’s version of Javascript, but I believe when you use #pragma strict you have to include a data type, or initialize the variable to a value that the compiler can use to infer the type, when declaring a variable.
e.g.
var curAmmo = 20;
Without that, the compiler can’t infer the type, so is likely assuming it’s an object.