You are trying to create a MonoBehaviour using the new keyword. This is not allowed

Hello,

So I have seen this problem before but my class is not a child of MonoBehaviour! Shouldn’t this not happen?

Here’s (shortly) the code:

public class FirstBossHeadScript : MonoBehaviour {

public EnemyStats thisenemy = new EnemyStats();

public void Start()
{

    thisenemy.maxHealth = 10;
 }

}

Here’s the EnemyStats class:

    public class EnemyStats {

    public int maxHealth = 100;
    }

Try moving new inside the start function like this.

 public class FirstBossHeadScript : MonoBehaviour {
 
 public EnemyStats thisenemy ;
 public void Start()
 {
     thisenemy = new EnemyStats();
     thisenemy.maxHealth = 10;
  }

Umm, just stumbled upon this. The error message is because Unity doesn’t Allow creation of MonoBehaviour classes with the keyword new.
Instead use GameObject.Instantiate.