- Home /
what am I doing wrong
I have a contoller script that my playerstats derives from. I want to put it on my main camera so that when you hit play the stats of each character here is what I am working with:
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(PlayerStats))]
public class Controller : MonoBehaviour {
public PlayerStats _jake;
void Start(){
_jake.level = 3;
_jake.STR = 50;
_jake.DEX = 55;
_jake.DEF = 50;
_jake.vital = 100;
_jake.Magic = 60;
_jake.luck = 45;
_jake.Speed = 56;
_jake.Agility = 46;
_jake.exp.Cur = 0;
}
}
note:Jake is just one of the characters that need this script there are four more party members too. here is PlayerStats:
public class PlayerStats : Controller {
public int level;
public string name;
public Stat Hp = new Stat();
public Stat Mp = new Stat();
public int STR;
public int DEX;
public int DEF;
public int vital;
public int Magic;
public int luck;
public int Speed;
public int Agility;
public int melee;
public int ranged;
public int MagA;
public int MagD;
public float active;
public Stat exp = new Stat();
public void addexp(int ex){
exp.Cur += ex;
while(exp.Cur >= exp.Max && level < 99){
exp.Cur -= exp.Max;
exp.Max = level *(level+1)* 500;
level++;
upstats();
}
}
void upstats(){
STR++;
DEX++;
DEF++;
vital++;
Magic++;
luck++;
Speed++;
Agility++;
melee =(level*7)+STR;
ranged =(level*7)+DEX;
DEF =(level*2)+ Agility;
MagA =(level*7)+ Magic;
MagD =(level*2)+ luck;
active =20+((Speed * level)/1500);
Hp.Max =((level * 5)+ vital)*10;
Hp.Cur = Hp.Max;
Mp.Max =((level * 5)+ Magic)*10;
Mp.Cur = Mp.Max;
}
public class Stat{
public int Cur;
public int Max;
}
public PlayerStats(int level,string name,int STR,int DEX,int DEF,int vital,int Magic,int luck,int speed,int Agility,int exp){
this.level = 1;
this.name = name;
this.STR = STR;
this.DEF = DEF;
this.vital = vital;
this.Magic = Magic;
this.luck = luck;
this.Speed = speed;
this.Agility = Agility;
addexp(exp);
}
}
this script runs from the Project tab. and the controller script attaches to camera because it is for my characters all 5 of them who are in the party. I also am getting an error that says stack overflow extintion
could you please provide some more info on what you are upto....
this is the other script and I want to run each character in the inpector
Answer by MaGuSware™ · Dec 24, 2012 at 09:43 AM
If I am understanding what it is you are wanting to do, you need to add [System.Serializable] above your PlayerStats class.
That's because in the controller you have public PlayerStats _jake;
Your player stats inherit off controller. For every controller you have a new playerstats, which creates a new controller... which creates a new playerstats and so on and so on until you run out of memory.
-edit- Basically you need to make PlayerStats not inherit from Controller.
Your answer
Follow this Question
Related Questions
Please help with Unity Forums C# 1 Answer
SelectTarget Does not exist Current Context 1 Answer
Show Strings With Last Characters of the first Word 1 Answer
Problem with text blinking 1 Answer
Die Function Help With C# 1 Answer