Hello, I made a script here that I want to give you more ammo when you collide with it. But I keep getting this error: Assets/AmmoPickup.js(14,9): BCE0005: Unknown identifier: ‘ammo’.
Here is the code for the destroy and give ammo:
(AmmoPickup.js)
var playerObject : GameObject;
private var myGO : GameObject;
function Start()
{
myGO = gameObject;
}
function OnTriggerEnter (other : Collider) {
if (!other.CompareTag("Player")) return; //Check that it's the player that triggers else exit the function
myGO.active = false; //Disable this GameObject
ammo.GetComponent(Ammo).ammo += 10;
{
ammo = GameObject.Find("First Person Controller").GetComponent(Ammo);
}
}
and here is the ammo script:
(Ammo.js)
var ammo : float;
var fireRate : float = 0.5;
var style : GUIStyle;
private var nextFire : float = 0.0;
private var shooting : boolean = true;
private var flames : boolean = true;
function OnGUI() {
GUI.color = Color.red;
GUI.Label(Rect(20, 20, 200, 200), "MANA: " + ammo, style);
if(Input.GetMouseButtonDown(0) && Time.time > nextFire){
nextFire = Time.time + fireRate;
ammo -= 1;
{
if(ammo < 0)
shooting = false;
flames = false;
}
}
if(shooting == false){
GameObject.Find("Actual").GetComponent(MagicShoot).active = false;
GameObject.Find("small flames").active = false;
}
else
{
GameObject.Find("Actual").GetComponent(MagicShoot).active = true;
GameObject.Find("small flames").active = true;
}
}