Unity BurgZergArcade Tutorial 20 errors.

So I have been following BurgZergArcade’s unity tutorials and i have been loving it but i am up to 20 and ever since i started 18-20(BaseCharacter.cs Tutorials) i have been getting errors in my BaseCharacter Script, There are like 5 main errors than they start to repeat. It seems it cant get access to my other classes. Here are some errors:

Assets/Scripts/Character Classes/BaseCharacter.cs(124,57): error CS1503: Argument #1' cannot convert object’ expression to type `ModifyingAttribute’

Assets/Scripts/Character Classes/BaseCharacter.cs(124,57): error CS1502: The best overloaded method match for `ModifiedStat.AddModifier(ModifyingAttribute)’ has some invalid arguments

Assets/Scripts/Character Classes/BaseCharacter.cs(124,149): error CS1729: The type ModifyingAttribute' does not contain a constructor that takes 2’ arguments

Assets/Scripts/Character Classes/BaseCharacter.cs(124,92): error CS1503: Argument #1' cannot convert object’ expression to type `int’

Assets/Scripts/Character Classes/BaseCharacter.cs(124,92): error CS1502: The best overloaded method match for `BaseCharacter.GetPrimaryAttribute(int)’ has some invalid arguments

Assets/Scripts/Character Classes/BaseCharacter.cs(124,117): error CS0103: The name `AttributeName’ does not exist in the current context

Assets/Scripts/Character Classes/BaseCharacter.cs(33,56): error CS1502: The best overloaded method match for `System.Enum.GetValues(System.Type)’ has some invalid arguments

-------------------------------Fin

And here is my code or script:

using UnityEngine;
using System.Collections;
using System; //added to acess enum class
using System.Collections.Generic;

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 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++){
		_primaryAttribute[cnt] = new Attribute();
	}		
}

private void SetupSkills(){
	for(int cnt = 0; cnt <_skill.Length; cnt++){
		_primaryAttribute[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.Constitution), .5f));
	//energy
	GetVital((int)VitalName.Energy).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Constitution), 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.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();	
	
}	

}
----------------------------fin

So if you could find my errors it would mean the world to me, this series means alot to me and it is very interesting and i would hate to get stuck here. Ask me any questions if you need more info.

Thank you so much.

Okay Here we go:

Assets/Scripts/Character
Classes/BaseCharacter.cs(124,57):
error CS1503: Argument #1’ cannot
convertobject’ expression to type
`ModifyingAttribute’

you are missing curly brackets for your ModifyingAttribute object you are creating. you are using parenthesis, on accident!

Do it like this (Unity 3):


GetVital((int) VitalName.Health).AddModifier(new ModifyingAttribute { attribute = GetPrimaryAttribute((int) AttributeName.Constitution), ratio = 0.5 });


I bolded the part you got wrong.

Assets/Scripts/Character
Classes/BaseCharacter.cs(124,57):
error CS1502: The best overloaded
method match for
`ModifiedStat.AddModifier(ModifyingAttribute)’
has some invalid arguments

Assets/Scripts/Character
Classes/BaseCharacter.cs(124,149):
error CS1729: The type
ModifyingAttribute’ does not contain a
constructor that takes2’ arguments

Same thing for these as well… looks like the other errors might be related.

let me explain what is going on…

You are running the method GetVital(), [and passing in an (int) you are getting from an enumeration], and then after that, running AddModifier().

The problem is in the second function, “AddModifier()”

the problem is the argument you are passing into the Add Modifier. The AddModifier expects an object that is of type ModifyingAttribute. In your case, since you are missing those brackets… the compiler thinks you are passing objects of the wrong type! In truth… the new ModifyingAttribute is what needs that int for its first argument, attribute.

So basically each AddModifier takes 2 args: the attribute, which takes an Attribute, and the ratio which takes a float (or double in my project). the Attribute is returned from GetPrimaryAttribute(). GetPrimaryAttribute() takes an int. We are getting the int by casting an enum as an int.

so swap those parenthesis for curly brackets to properly ‘new up’ what you need!

Edit: to be clear, I think it goes without saying you made the exact same mistake on every VitalModifier line and SkillModifierLine. thats why you have a bunch of duplicate errors. Check out Petey’s video again,and you’ll see the slip up. If you want to learn more about this technique its called Object Initializers. Read more here: http://msdn.microsoft.com/en-us/library/bb397680.aspx

And be sure to mark this as the answer if it fixed your code.