- Home /
script needs to derive from monobehaviour
Hello I was working on character system for my new game but I am getting script needs to derive from monobehaviour error when I try to attach it.
Here is the code:
#pragma strict
var player1 : Character;
function Start ()
{
player1.name = "Esporta";
player1.money = 100;
player1.level = 1;
player1.job = "unemployed";
}
//
//
//
public class Character : MonoBehaviour
{
var name;
var money;
var level;
var job;
}
Answer by Landern · Aug 19, 2014 at 02:35 PM
You used the c# syntax not the unityscript:
public class Character extends MonoBehaviour
{
var name;
var money;
var level;
var job;
}
Checkout the unityscript newbie guide: Newbie Guide to UnityScript
Please post as a comment, not answer.
The error is different, it's not the same, try instantiating the player.
#pragma strict
var player1 : Character;
function Start ()
{
player1 = Character();
player1.name = "Esporta";
player1.money = 100;
player1.level = 1;
player1.job = "unemployed";
}
class Character extends $$anonymous$$onoBehaviour
{
var name: String;
var money: int;
var level: int;
var job: String;
}
Still same problem,
Here is the error I am getting ^ and still getting script needs to derive from monobehaviour error when I try to attach script to any object Here is the code
#pragma strict
var player1 : Character;
function Start ()
{
player1 = Character();
player1.name = "Esporta";
player1.money = 100;
player1.level = 1;
player1.job = "unemployed";
}
//
//
//
//
public class Character extends $$anonymous$$onoBehaviour
{
var name: String;
var money: int;
var level: int;
var job: String;
}
Your answer
Follow this Question
Related Questions
How to Typecast JS Variables as C# Classes? 0 Answers
Is it possible to create a script dinamic like animation>size controling the Elements variables? 1 Answer
Different way to access class variables? 1 Answer
Creating A Class Variable That Works With Any Class 0 Answers
Accessing a variable inside a class inside other script... 2 Answers