- Home /
Help! error CS0101 : The namespace 'global::' already contains a definition for 'StatyPostaci;
using UnityEngine;
using System.Collections;
public class StatyPostaci : MonoBehaviour {
private float MaxZycie = 100;
public float AktualneZycie = 100;
private float MaxNawodnienie = 100;
public float AktualneNawodnienie = 100;
private float MaxGlod = 100;
public float AktualnyGlod = 100;
public Texture2D ZycieTextura;
public Texture2D NawodnienieTextura;
public Texture2D GlodTextura;
private float barWidth;
private float barHeight;
public float timerGlodu = 40;
public float timerNawodnienia = 10;
public float timerZycia = 5;
void Awake() {
barHeight = Screen.height * 0.02f;
barWidth = barHeight * 10.0f;
}
void OnGUI() {
GUI.DrawTexture (new Rect (Screen.width - barWidth - 10,
Screen.height - barHeight - 10,
AktualneZycie * barWidth / MaxZycie,
barHeight), ZycieTextura);
GUI.DrawTexture (new Rect (Screen.width - barWidth - 10,
Screen.height - barHeight * 2 - 10,
AktualneNawodnienie * barWidth / MaxNawodnienie,
barHeight), NawodnienieTextura);
GUI.DrawTexture (new Rect (Screen.width - barWidth - 10,
Screen.height - barHeight * 3 - 10,
AktualnyGlod * barWidth / MaxGlod,
barHeight), GlodTextura);
}
void Start () {
}
void Update () {
if (AktualneZycie <= 0) {
AktualneZycie = 0;
}
if (AktualnyGlod <= 0) {
AktualnyGlod = 0;
}
if (AktualneNawodnienie <= 0) {
AktualneNawodnienie = 0;
}
if (AktualneNawodnienie >=100) {
AktualneNawodnienie = 100;
}
if (AktualneZycie >=100) {
AktualneZycie = 100;
}
if (AktualnyGlod >=100) {
AktualnyGlod = 100;
}
timerGlodu -= Time.deltaTime;
timerNawodnienia -= Time.deltaTime;
if (timerGlodu <= 0) {
AktualnyGlod -= 20;
timerGlodu = 40;
}
if (timerNawodnienia <= 0) {
AktualneNawodnienie -= 5;
timerNawodnienia = 10;
}
if (AktualnyGlod <= 1) {
timerZycia -= Time.deltaTime;
if(timerZycia <=0){
AktualneZycie -= 5;
timerZycia = 5;
}
}
}
}
Line 5
Answer by KittenSnipes · Jan 21, 2018 at 10:15 AM
What I did to fix this was delete the script, copy the code, close unity, reopen it, reload the project, remake the exact script and then paste my code. There could be better ways but it is what I always do when I get that error.
No problem glad I could help :D
The error means that you have two classes with the same name on the same namespace that being global, as it is unspecified. To fix it either change the name of either one or move either or both inside a different namespace. As why this fix works its probably if you create and delete a class with same name multiple times probably it fails to reload/recreate properly the assembly, in which occasion just reloading the assemblies should fix the issue.
Cheers!
Your answer
Follow this Question
Related Questions
My Unity is buggy after 5.6.0 update 1 Answer
Cannot paint textures onto terrain, errors are raised 0 Answers
Games runs perfectly on editor but error on build 1 Answer
"Could Not Produce Class with ID 1108" error 0 Answers
If you solve my this problem I`ll give you 100 points. My problem is --Cannot download entry--. 1 Answer