Can anyone help me with a simple CSharp error

Hi all
I keep getting error code CS0116 & CS0122 in CSharp

Heres the code im working on:

using UnityEngine;
using System.Collections;

public class BaseEntity : MonoBehaviour 

{

	protected float mHealth = 100.0f;
	public float currentHealth{get{return mHealth;}}
	
	protected float mMaxhealth = 100.0f;
	public float maxHealth{get{Type{return mMaxhealth;}}}

	public virtual void takeDamage (float amount);

}

{    ***ERROR CODE CS1016:namespace does not directly contain members***

    if (mHealth <=0)
	mHealth =amount;

}    ***ERROR CODE CS1022:Type or namespace definition, or end-of-file expected***

{
		die();

	

	  public virtual void healDamage (float amount)
	  mHealth = Mathf.Min (mHealth + amount, mMaxHealth);
	  protected virtuel void die ()
	  Destroy(gameObject);

}

There are multiple things completely wrong with that code. O_O syclamoth pointed out a few of them. I pasted your code into Visual Studio and cleaned it up. Here’s what I came up with:

using UnityEngine; 
using System.Collections;

public class BaseEntity : MonoBehaviour {

    protected float mHealth = 100.0f;
    public float currentHealth{get{return mHealth;}}

    protected float mMaxhealth = 100.0f;
    public float maxHealth{get{return mMaxhealth;}}

    private void Update() // Added by Christian H. Pedersen. Your if-sentence, that checks the health, did not exist inside any method. I assumed you wanted to check once per frame?
    {
        if (mHealth <= 0)
        {
            //mHealth = amount; Commented out - The variable "amount" does not exist in this scope. What did you want to set mHealth to?
            die(); // Kept in. It makes sence that the entity dies if its health is reduced to 0 or below.
        }
    }

    public virtual void healDamage (float amount)
    {   
        mHealth = Mathf.Min (mHealth + amount, mMaxhealth);
    }
  
    protected virtual void die ()
    { 
        Destroy(gameObject);
    }
}

Judging from the code you posted originally, it looks like you’re in dire need of a proper editor. Whatever you’re coding in now doesn’t indent code properly, which makes it harder for you to keep track of your curly braces. Before you do anything more, get a proper editor, like Visual Studio or at least MonoDevelop.

Secondly, I corrected several errors that were either typos or syntactic errors. For example, the “maxHealth” property you’ve defined had the word “Type” in front of the block that returns the variable. This makes no sense. You also misspelled “virtual” in the declaration of die, and the identifier “mMaxhealth” was referenced as “mMaxHealth”, which did not exist (note the upper case “H”).

Anyway, there’s the suggestion. Maybe that’s what you intended to write. :slight_smile: Once again: Get a proper editor, it’ll help a lot.