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 delorean225 · Jun 09, 2013 at 05:37 PM · enemydeathvarwave

Public Variable Help!

In my game, I'm trying to make a wave spawner, so that when every enemy dies it will start a new wave. Right now, either the death line or the variable itself is broken. Here's my monster death system:

 var Health : float = 100;
 var MaxHealth : float = 100;
 var Manager : GameObject;
 
 function OnTriggerEnter(hit : Collider){
 if (hit.CompareTag("EditorOnly")){
 Health = Health - 1;
 }
 }
 
 function Update(){
 if (Health <= 0){
 Manager.livingCreatures = Manager.livingCreatures - 1;
 Destroy(gameObject);
 }
 }

And my Wave script (I modified it from an existing one):

     var totalCreatures : int = 2; 
     static var livingCreatures : int = 0;
     var waitToWave : float = 10;
     var waveTime : float;
     var yourCreature : Transform;
     var CurrentWave : float = 1;
     var text : GUIText;
     
     function Update() {
      text.text = CurrentWave.ToString();
         if (livingCreatures == 0) {
      
             if (waitToWave <= waveTime) {
                 waveTime = 0;
                 livesCreatures = totalCreatures;
      
                 for (var i = 0; i > totalCreatures; i++) 
                     Instantiate (yourCreature, Vector3(0,0,0), Quaternion.identity);
                     totalCreatures = totalCreatures * 2;
                      CurrentWave = CurrentWave + 1;
             }else {
                 waveTime += Time.DeltaTime;
             }
         }
     }

It's getting an error that says "NullReferenceEception: Object reference not set to an instance of an object." Please help!

Comment
Add comment · Show 8
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 InfiniBuzz · Jun 09, 2013 at 05:57 PM 0
Share

Which line is indicated in the error message? $$anonymous$$ake sure you have set something for each variale in the inspector. Have you set the $$anonymous$$anager, yourCreature, text and waveTime variables?

avatar image Immanuel-Scholz · Jun 09, 2013 at 08:14 PM 0
Share

Without telling in which line the error is, we can only do guesswork.

For example, my guess is that you forgot to initialize your GUIText in the Editor.

avatar image delorean225 · Jun 09, 2013 at 08:16 PM 0
Share

It doesn't say a line number (i.e. (23, 26)). It says like "Boo.Lang." something...

avatar image Immanuel-Scholz · Jun 09, 2013 at 08:25 PM 0
Share

Since both of your scripts seem to be in JavaScript ins$$anonymous$$do of Boo, the error might relate to something completely else. Can you post the whole error text? And are you sure the error is even in one of these files?

avatar image InfiniBuzz · Jun 09, 2013 at 08:26 PM 0
Share

again, did you check that you have defined all the public variables in the inspector?

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Smireles · Jun 09, 2013 at 11:26 PM

I noticed a possible error that may be the cause of your code issue.

In your monster code at line 14:

 Manager.livingCreatures = Manager.livingCreatures - 1;

It should be:

 Manager.GetComponent('WaveSpawn').livingCreatures = Manager.GetComponent('WaveSpawn').livingCreatures - 1;

And probably changing in your WaveSpawn script:

 static var livingCreatures : int = 0;

for:

 public var livingCreatures : int = 0;

That's it. The rest of the code looks good. At least from here hehe. Try adding some Debug.Logs every here and there so you know exactly how far your code ran before crashing.

Good luck.

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
avatar image
0

Answer by delorean225 · Jun 10, 2013 at 08:24 PM

Solved it! If anyone would like to see the final code, I can show you. Thank you all for helping me, and I know where to go next time I have a problem.

Comment
Add comment · Show 1 · 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
avatar image Smireles · Jun 10, 2013 at 09:42 PM 0
Share

Hey! If a comment or answer helped you solve your problem do not forget to give it a "thumbs up". Only if it helped you.

Glad to hear that you solved your problem. Cheers :)

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

16 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 avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Player Health and Death 1 Answer

Enemy healthbar script 2 Answers

Enemy AI help 1 Answer

Enemies not shooting laser on certain level 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