Need help with fixing errors

Hi,

I have managed to code this but its coming up with lots of errors and idk how to fix them :S

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(SkillName)).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 average of all of the players skills and assign that as 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 Attribute();
		}
	}
	
	private void SetupSkills() {
		for(int cnt = 0; cnt < _skill.Length; cnt++) {
			_skill[cnt] = new Attribute();
		}
	}
	
	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
		GetVital((int)VitalName.Health).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Constituion), .5f));
		//stamina
		GetVital((int)VitalName.Stamina).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Constituion), .1));
		//mana
		GetVital((int)VitalName.Mana).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Willpower), .1));
	}
	
	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.Constituion), .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.Willpower), .33f));
		//Ranged Defence
		GetSkill((int)SkillName.Ranged_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Concentration), .33f));
		GetSkill((int)SkillName.Ranged_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Willpower), .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 ();
	}
}

The Errors are:

  1. Assets/Standard Assets/GeneralScripts/Character Classes/BaseCharacter.cs(63,25): error CS0029: Cannot implicitly convert type Attribute' to Vital’

  2. Assets/Standard Assets/GeneralScripts/Character Classes/BaseCharacter.cs(69,25): error CS0029: Cannot implicitly convert type Attribute' to Skill’

  3. Assets/Standard Assets/GeneralScripts/Character Classes/BaseCharacter.cs(89,141): error CS1502: The best overloaded method match for `ModifyingAttribute.ModifyingAttribute(Attribute, float)’ has some invalid arguments

  4. Assets/Standard Assets/GeneralScripts/Character Classes/BaseCharacter.cs(89,141): error CS1503: Argument #2' cannot convert double’ expression to type `float’

  5. Assets/Standard Assets/GeneralScripts/Character Classes/BaseCharacter.cs(89,50): error CS1502: The best overloaded method match for `ModifiedStat.AddModifier(ModifyingAttribute)’ has some invalid arguments

  6. Assets/Standard Assets/GeneralScripts/Character Classes/BaseCharacter.cs(89,50): error CS1503: Argument #1' cannot convert object’ expression to type `ModifyingAttribute’

  7. Assets/Standard Assets/GeneralScripts/Character Classes/BaseCharacter.cs(91,136): error CS1502: The best overloaded method match for `ModifyingAttribute.ModifyingAttribute(Attribute, float)’ has some invalid arguments

  8. Assets/Standard Assets/GeneralScripts/Character Classes/BaseCharacter.cs(91,136): error CS1503: Argument #2' cannot convert double’ expression to type `float’

  9. Assets/Standard Assets/GeneralScripts/Character Classes/BaseCharacter.cs(91,47): error CS1502: The best overloaded method match for `ModifiedStat.AddModifier(ModifyingAttribute)’ has some invalid arguments

  10. Assets/Standard Assets/GeneralScripts/Character Classes/BaseCharacter.cs(91,47): error CS1503: Argument #1' cannot convert object’ expression to type `ModifyingAttribute’

Sorry if i’m asking for too much help I am fairly new to C#.

Thanks

You can only assign objects of the same type or of a subclass to a variable.
E.g.:
Vital _vital = new Vital(); //OK
Vital _vital = new VitalSubClass(); //Ok as VitalSubClass inherits from Vital
Vital _vital = new WhateverClass(); //Wont work as type is not the same

Thanks for the help :slight_smile: