Can anyone help? Assets/PlayerInfo.cs(5,14): error CS0101: The namespace `global:....

I keep getting this error: Assets/PlayerInfo.cs(5,14): error CS0101: The namespace global::' already contains a definition for PlayerHealth’ , does anyone know the reason why this occurs?

using UnityEngine;
using System.Collections;

public class PlayerInfo : MonoBehaviour {

public GameObject Player;
int health = 100;
int damageCount = 0;
int currentHealth;
bool playerFighting;
public GUIText HealthBar;
float timer = 0.0f;
// Use this for initialization
void Start () {
currentHealth = health;
Screen.showCursor = false;
}

// Update is called once per frame
void Update () {

print (“Player in combat” + playerFighting);
}
public void ApplyDamage(int damage)
{
damageCount = damageCount;
if(damageCount == 100)
{
currentHealth = currentHealth - 10;
HealthBar.text = “Health” + currentHealth + “/ 100”;
damageCount = 0;
}
}

public void playerInCombat(int combat){
if (combat == 1) {
playerFighting = true;
} else {
playerFighting = false;
}
}
}

using UnityEngine;
using System.Collections;

public class PlayerInfo : MonoBehaviour {

public GameObject Player;
int health = 100;
int damageCount = 0;
int currentHealth;
bool playerFighting;
public GUIText HealthBar;
float timer = 0.0f;
// Use this for initialization
void Start () {
currentHealth = health;
Screen.showCursor = false;
}

// Update is called once per frame
void Update () {

print (“Player in combat” + playerFighting);
}
public void ApplyDamage(int damage)
{
damageCount = damageCount;
if(damageCount == 100)
{
currentHealth = currentHealth - 10;
HealthBar.text = “Health” + currentHealth + “/ 100”;
damageCount = 0;
}
}

public void playerInCombat(int combat){
if (combat == 1) {
playerFighting = true;
} else {
playerFighting = false;
}
}
}

using UnityEngine;
using System.Collections;

public class PlayerInfo : MonoBehaviour {

public GameObject Player;
int health = 100;
int damageCount = 0;
int currentHealth;
bool playerFighting;
public GUIText HealthBar;
float timer = 0.0f;
// Use this for initialization
void Start () {
currentHealth = health;
Screen.showCursor = false;
}

// Update is called once per frame
void Update () {

print (“Player in combat” + playerFighting);
}
public void ApplyDamage(int damage)
{
damageCount = damageCount;
if(damageCount == 100)
{
currentHealth = currentHealth - 10;
HealthBar.text = “Health” + currentHealth + “/ 100”;
damageCount = 0;
}
}

public void playerInCombat(int combat){
if (combat == 1) {
playerFighting = true;
} else {
playerFighting = false;
}
}
}

Please use Code tags to make it easier to read your code. That being said, when you don’t put things in a Namespace it actually puts them in the ‘global’ namespace. So what the error means is that you have another class called PlayerHealth that doesn’t have a namespace. You’ll either have to put one in a namespace or you’ll have to rename one to something else.

1 Like

Thank you very much! How do I use code tags though?

[CODE]
Your Code Here
[/CODE]