Hi there,
I’ve seen a few posts about using Javascript files as classes and fixing the warning:
You are trying to create a
MonoBehaviour using the ‘new’ keyword.
This is not allowed. MonoBehaviours
can only be added using
AddComponent(). Alternatively, your
script can inherit from
ScriptableObject or no base class at
all
However I’m not sure how to apply the solution to my game. I have a Javascript class as follows:
public var networkPlayer : int;
public var playerName : String;
public var playerScore : int;
public var playerTeam : String;
public function PlayerDataClass() : PlayerDataClass
{
var capture : PlayerDataClass = new PlayerDataClass();
capture.networkPlayer = networkPlayer;
capture.playerName = playerName;
capture.playerScore = playerScore;
capture.playerTeam = playerTeam;
return capture;
}
So in a separate script (PlayerDatabase.js) I declare at the top:
public var PlayerList : List.<PlayerDataClass> = new List.<PlayerDataClass>();
And then:
function AddPlayerToList(nPlayer : NetworkPlayer)
{
var capture : PlayerDataClass = new PlayerDataClass();
capture.networkPlayer = int.Parse(nPlayer.ToString());
PlayerList.Add(capture);
}
So I’m not sure if AddComponent() will work how I need it to? Any help would be incredible!