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
1
Question by Nahoyman78 · Apr 21, 2012 at 01:28 PM · errorstartvoidsmall

A Script error With Void Start

Hi Guys :) I need help to figure out what thing that Occurs THIS Annoying Error :(. So here is the Script:

using UnityEngine; using System.Collections;

public class VitalBar : MonoBehaviour { private bool _isPlayerHealthBar

 void Start() {
     
     _isPlayerHealthBar = true;
     
     OnEnable();
 }
 
 // Update is called once per frame
 void Update () {
 
 }
 
 public void OnEnable() {
     if(_isPlayerHealthBar)
     Messanger<int, int>.AddListener("Player Health Update", OnChangeHealthBarSize);
     else
         Messanger<int, int>.AddListener("No Health Update", OnChangeHealthBarSize);
 }
 
 public void OnDisable() {
     if(_isPlayerHealthBar)
     Messanger<int, int>.AddListener("Player Health Update", OnChangeHealthBarSize);
     else
         Messanger<int, int>.AddListener("No Health Update", OnChangeHealthBarSize);
     
 }
 
 public void ChangeHealthBarSize(int currHealth, int maxHealth) {
     Debug.Log("We heard an event: currHealth = " + currHealth + " - maxHealth = " + maxHealth);
     
 }
 
 public void SetPlayerHealth(bool b) {
     _isPlayerHealthBar = b;
     
 }

}

Any ideas xD?

EDIT: FIXED xD

Comment
Add comment
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

2 Replies

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

Answer by aldonaletto · Apr 21, 2012 at 01:33 PM

You forgot to mention which error you've got! Anyway, in the script posted there's a missing ";" in the variable declaration, what could cause an error in void Start():

   private bool _isPlayerHealthBar; //<- this semicolon was missing!
Comment
Add comment · Show 6 · 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 Nahoyman78 · Apr 21, 2012 at 02:12 PM 0
Share

Thanks guys xD

avatar image Nahoyman78 · Apr 21, 2012 at 02:15 PM 0
Share

But now when i try. This Error Comes:

  1. Assets/Scripts/VitalBar.cs(21,17): error CS0103: The name $$anonymous$$essenger2' does not exist in the current context

4 Times! :O

avatar image Kleptomaniac · Apr 21, 2012 at 02:15 PM 0
Share

If either or both of these answers helped you, you should acknowledge this by accepting their answers (ticking them).

Also, please don't post comments as answers.

avatar image Nahoyman78 · Apr 21, 2012 at 02:47 PM 0
Share

Any Ideas :)?

avatar image Kleptomaniac · Apr 21, 2012 at 03:09 PM 1
Share

Well, I don't know what you are talking about in terms of '$$anonymous$$essenger2'. $$anonymous$$essenger2 does not occur as an identifier at all in the script. In this case, I believe you mean $$anonymous$$essenger? However, $$anonymous$$essenger is referenced within the script but it is never initialised anywhere in the script?

That's what's causing your error.

Show more comments
avatar image
1

Answer by unfoundfate · Apr 21, 2012 at 01:33 PM

private bool _isPlayerHealthBar needs semicolon

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Enexpected Symbol Void (start) 1 Answer

Not expecting void Start 2 Answers

Start() of Instantiated Prefabs Not Being Carried Out? 1 Answer

How do I access variables initialized in a start function from another script? 1 Answer

My void Start won't work 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