0

I want to try a unity project from different version. the project is unity 5, and my unity is 2020 2.7f1. while I open the project, I had this warning

screenshot of warning i had

it said that "new" keyword is not allowed and I don't understand how to fix this

this is the code from FuzzySet.cs

public string[] tenBNN = new string[10];

//so bien ngon ngu
public int SoBNN = 0;
public FuzzySet(string a)
{
    _name = a;
}

and this is from Speed_Control.cs

public static FuzzySet Foresight = new FuzzySet("Foresight");
public static FuzzySet RoadWidth = new FuzzySet("Road Width");
public static FuzzySet CarInFront = new FuzzySet("Cars in front");
public static FuzzySet Distance = new FuzzySet("Distance to the intersection");
public static FuzzySet Speed = new FuzzySet("Safe Speed");
  • This warning just says that you are creating a new object which happens to be a Monobehaviour class using the standard approach (using "new" keyword). Monobehaviour must be created another way (by adding them as a component on a game object). – rootpanthera Jun 14 '21 at 06:30
  • Check this link if it can help: https://docs.unity3d.com/ScriptReference/GameObject.AddComponent.html – Adrien G. Jun 14 '21 at 06:50
  • For reference purposes, please don't add text as images. – Dominique Jun 14 '21 at 08:05
  • The error is pretty self-explanatory .. Do **NOT** use `new` for classes that inherit from `MonoBehaviour` .. also see e.g. [Unity: Null while making new class instance](https://stackoverflow.com/questions/37398538/unity-null-while-making-new-class-instance) => Does your class `FuzzySet` really have to be a `MonoBehaviour` at all? – derHugo Jun 14 '21 at 08:27

0 Answers0