- Home /
Global Variables Refuse to Cooperate
I have a gun. It has a variable clips.
Here is the scripts.
 var canShoot : boolean = true;
 var ammo = 17;
 static var clips : int = 3;
 var reloadTime = 5.228;
 var reloadSound :AudioClip;
 var shootSound : AudioClip;
 var Force : float = 200;
 var RangeOfGun : float = 4000000;
 var anim ="ShootGun";
 var gun : GameObject;
 var gunModel : GameObject;
 function FireGun() {
     var Hit : RaycastHit;
     if (ammo !=0) {    
     var DirectionRay = transform.TransformDirection(Vector3.forward);
     Debug.DrawRay(transform.position, DirectionRay * RangeOfGun, Color.blue);
     if (Physics.Raycast(transform.position, DirectionRay, Hit, RangeOfGun)) {
     if (Hit.rigidbody) {
     shootGun();
     Hit.rigidbody.SendMessage("ApplyDamage", Random.Range(20,58), SendMessageOptions.DontRequireReceiver);
     ammo = ammo - 1;
     }
     else {
     shootGun();
     ammo = ammo -1;
     }
     }
     }
 }
 function Update () {
 if (canShoot == true) {    
 if(Input.GetMouseButtonDown(0)) {
     FireGun();
 }
 if (Input.GetMouseButtonDown(0) && ammo == 0 && clips > 0) {
 reload();
 }    
 }
 }
 function shootGun() {
 audio.PlayOneShot(shootSound);
 gun.animation.Play(anim);
 }
 function reload() {
 canShoot = false;
 gunModel.animation.Play("ReloadGun");
 audio.PlayOneShot(reloadSound);
 yield WaitForSeconds(reloadTime);
 ammo = 17;
 clips = clips-1;
 canShoot = true;
 }
And I have what will soon be ammo boxes. That's my problem.
 var player : GameObject;
 var gun : GameObject;
 function OnTriggerEnter(objectentered : Collider) {
 
     if(objectentered.name=="First Person Controller") {
     
     Debug.Log("Character Hit");
         Debug.Log(BulletScript.clips);
             BulletScript.clips = BulletScript.clips + 2;
         
         
     }    
 }
It REFUSES to work. I have spent several hours trying to make it work.
The error -
"Assets/Standard Assets/Character Controllers/Sources/Scripts/Collide.js(8,27): BCE0005: Unknown identifier: 'BulletScript'."
Someone, Please ease my pain.
Thanks for helping :)
the error speaks for itself, the script of the static vars what's the name? Because the compiler is saying that BulletScript was not found, that isn't exist!
@RafaelCN That's why I got so pissed. It's called EXACTLY "BulletScript". And it just wouldn't recognize it.
Answer by SilentWaffle524 · May 05, 2013 at 02:25 AM
I have found my answer. I decided to not use static vars and instead do gun.getComponent("BulletScript").clips.
Your answer
 
 
             Follow this Question
Related Questions
Increase Static Var gradually 1 Answer
How to use same code at multiple scenes ? 1 Answer
Script effects all gameobjects. 1 Answer
Not asigned health script 1 Answer
Quick question about global variables. Two ways. Are they different? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                