Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by SilentWaffle524 · May 04, 2013 at 11:40 PM · triggervariablevariablesstaticglobal

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 :)

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RafaelCN · May 05, 2013 at 02:22 AM 0
Share

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!

avatar image SilentWaffle524 · May 05, 2013 at 05:27 PM 0
Share

@RafaelCN That's why I got so pissed. It's called EXACTLY "BulletScript". And it just wouldn't recognize it.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges