Sorry, I know you guys are probably sick of me asking for help but i’ve run into another error that I have no idea how to fix. The errors are saying:
Assets/Scripts/Character Classes/CharacterGenerator.cs(25,29): error CS1503: Argument #2' cannot convert object’ expression to type `string’
Assets/Scripts/Character Classes/CharacterGenerator.cs(25,29): error CS1502: The best overloaded method match for `UnityEngine.GUI.Label(UnityEngine.Rect, string)’ has some invalid arguments
Assets/Scripts/Character Classes/CharacterGenerator.cs(25,81): error CS1061: Type PlayerCharacter' does not contain a definition for GetPrimaryAttribute’ and no extension method GetPrimaryAttribute' of type PlayerCharacter’ could be found (are you missing a using directive or an assembly reference?)
and here is my script:
public class CharacterGenerator : MonoBehaviour {
private PlayerCharacter _toon;
// Use this for initialization
void Start () {
_toon = new PlayerCharacter();
_toon.Awake();
}
// Update is called once per frame
void Update () {
}
void OnGUI() {
GUI.Label(new Rect(10, 10, 50, 25), "Name");
_toon.name = GUI.TextArea(new Rect(65, 10, 100, 25), _toon.name);
for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++) {
GUI.Label(new Rect(10, 40 + (cnt * 25), 100, 25), ((AttributeName)cnt).ToString());
GUI.Label(new Rect(115, 40 + (cnt * 25), 30, 25), _toon.GetPrimaryAttribute(cnt).AdjustedBaseValue.ToString());
}
}
}
It’s not finished yet by the way.
I know by now you guys would be saying “learn C# script!” but I just can’t grasp even the basics of it. (my brain only seems to like to learn about stuff I don’t need at the moment)
From your other post it looks like GetPrimaryAttribute is a member of BaseCharacter not PlayerCharacter.
There are two things you can do to fix this. Either implement GetPrimaryAttribute for PlayerCharacter or make PlayerCharacter inherit from BaseCharacter. My guess is you would want to do the latter.
To do this, the first line of the PlayerCharacter definition should look like:
public string name = "Name";
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void Awake()
{
}
}
using UnityEngine;
using System.Collections;
using System; //added to access the enum class
public class BaseCharacter : MonoBehaviour {
private string _name;
private int _level;
private uint _freeExp;
private Attribute[] _primaryAttribute;
private Vital[] _vital;
private Skill[] _skill;
public void Awake() {
_name = string.Empty;
_level = 0;
_freeExp = 0;
_primaryAttribute = new Attribute[Enum.GetValues(typeof(AttributeName)).Length];
_vital = new Vital[Enum.GetValues(typeof(VitalName)).Length];
_skill = new Skill[Enum.GetValues(typeof(VitalName)).Length];
SetupPrimaryAttributes();
SetupVitals();
SetupSkills();
}
public string Name {
get{ return _name; }
set{ _name = value; }
}
public int level {
get{ return _level; }
set{ _level = value; }
}
public uint FreeExp {
get{ return _freeExp; }
set{ _freeExp = value; }
}
public void AddExp(uint exp) {
_freeExp += exp;
CalculateLevel();
}
// take avg of all players skills and assign that as the player level
public void CalculateLevel() {
}
private void SetupPrimaryAttributes() {
for(int cnt = 0; cnt < _primaryAttribute.Length; cnt ++) {
_primaryAttribute[cnt] = new Attribute();
}
}
private void SetupVitals() {
for(int cnt = 0; cnt < _vital.Length; cnt ++) {
_vital[cnt] = new Vital();
}
}
private void SetupSkills() {
for(int cnt = 0; cnt < _skill.Length; cnt ++) {
_skill[cnt] = new Skill();
}
}
public Attribute GetPrimaryAttribute(int index) {
return _primaryAttribute[index];
}
public Vital GetVital(int index) {
return _vital[index];
}
public Skill GetSkill(int index) {
return _skill[index];
}
private void SetupVitalModifiers() {
//health
ModifyingAttribute health = new ModifyingAttribute();
health.attribute = GetPrimaryAttribute((int)AttributeName.Constitution);
health.ratio = .5f;
GetVital((int) VitalName.Health).AddModifier(health);
//energy
ModifyingAttribute energyModifier = new ModifyingAttribute();
energyModifier.attribute = GetPrimaryAttribute((int)AttributeName.Constitution);
energyModifier.ratio = 1;
GetVital((int) VitalName.Health).AddModifier(energyModifier);
//mana
ModifyingAttribute manaModifier = new ModifyingAttribute();
manaModifier.attribute = GetPrimaryAttribute((int)AttributeName.Willpower);
manaModifier.ratio = 1;
GetVital((int) VitalName.Health).AddModifier(energyModifier);
}
private void SetupSkillModifiers() {
//melee offence
GetSkill((int)SkillName.Melee_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Might), .33f));
GetSkill((int)SkillName.Melee_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Nimbleness), .33f));
//melee defence
GetSkill((int)SkillName.Melee_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Speed), .33f));
GetSkill((int)SkillName.Melee_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Constitution), .33f));
//magic offence
GetSkill((int)SkillName.Magic_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Concentration), .33f));
GetSkill((int)SkillName.Magic_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Willpower), .33f));
//magic defence
GetSkill((int)SkillName.Magic_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Concentration), .33f));
GetSkill((int)SkillName.Magic_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Willpower), .33f));
//ranged offence
GetSkill((int)SkillName.Ranged_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Concentration), .33f));
GetSkill((int)SkillName.Ranged_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Speed), .33f));
//ranged defence
GetSkill((int)SkillName.Ranged_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Speed), .33f));
GetSkill((int)SkillName.Ranged_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Nimbleness), .33f));
}
public void StatUpdate() {
for(int cnt = 0; cnt < _vital.Length; cnt++)
_vital[cnt].Update();
for(int cnt = 0; cnt < _skill.Length; cnt++)
_skill[cnt].Update();
}
}
You will need to decide if you intend to code or not. If you insist on using C# you’ll have to learn the basics. Gibbonator is right. You didn’t include the the whole class in your “uhh” post so I can’t see what happened . Your last problems with the missing ‘Awake’ method and ‘name’ field were caused by the missing base as well. I tried to correct both of these.
public class PlayerCharacter : BaseCharacter {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
public class CharacterGenerator : MonoBehaviour
{
private PlayerCharacter _toon;
// Use this for initialization
void Start ()
{
_toon = new PlayerCharacter();
_toon.Awake();
}
// Update is called once per frame
void Update () {
}
void OnGUI() {
GUI.Label(new Rect(10, 10, 50, 25), "Name");
_toon.Name = GUI.TextArea(new Rect(65, 10, 100, 25), _toon.Name);
for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++) {
GUI.Label(new Rect(10, 40 + (cnt * 25), 100, 25), ((AttributeName)cnt).ToString());
GUI.Label(new Rect(115, 40 + (cnt * 25), 30, 25), _toon.GetPrimaryAttribute(cnt).AdjustedBaseValue.ToString());
}
}
}
You really should never have to come to a forum about compiler errors.
Google the bolded section of your errors (the part after 'error CSXXXX: ') and leave out the member names in quotes that are unique to your code.
Assets/Scripts/Character Classes/CharacterGenerator.cs(25,81): error CS1061: Type PlayerCharacter' does not contain a definition for GetPrimaryAttribute’ and no extension method GetPrimaryAttribute' of type PlayerCharacter’ could be found (are you missing a using directive or an assembly reference?)