- Home /
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
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!
But now when i try. This Error Comes:
Assets/Scripts/VitalBar.cs(21,17): error CS0103: The name
$$anonymous$$essenger
2' does not exist in the current context
4 Times! :O
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.
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.