- Home /
Namespace Errors
I am extremely new to C# and scripting in general. I am getting three errors in my script: Assets/Scripts/PlayerHealth.cs(25,14): error CS0116: A namespace can only contain types and namespace declarations
Assets/Scripts/PlayerHealth.cs(28,14): error CS0116: A namespace can only contain types and namespace declarations
Assets/Scripts/PlayerHealth.cs(31,21): error CS0116: A namespace can only contain types and namespace declarations
I have absolutely no clue what they mean or how to fix them. My full script is:
using UnityEngine;
using System.Collections;
public class PlayerHealth : MonoBehaviour {
public int maxHealth = 100;
public int curHealth = 100;
public float healthBarLength;
void Start() {
healthBarLength = (Screen.width / 1);
InvokeRepeating("HealthDrop", 9f, 9f);
}
void HealthDrop() {
curHealth -= 1;
}
}
void Update () {
AdjustCurrentHealth (0);
}
void OnGUI() {
GUI.Box (new Rect (4, 4, healthBarLength, 8), curHealth + "/" + maxHealth);
}
public void AdjustCurrentHealth(int adj) {
curHealth += adj;
if(curHealth < 0)
curHealth = 0;
if(curHealth > maxHealth)
curHealth = maxHealth;
if (maxHealth < 1)
maxHealth = 1;
healthBarLength = (Screen.width / 1) * (curHealth / (float)maxHealth);
}
Thank you for your time and any help.
Answer by Bunny83 · Dec 03, 2013 at 02:53 AM
Well, you close your class in line 21, so everything that comes after is not inside the class. You should move the curly bracket to the end of the file.
Your answer
