• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
-1
Question by suicidalcrow · May 02, 2013 at 01:33 PM · errornamespacecs0246

The type or namescape name 'ModifyingAttribute' could not be found.

Hey guys, I've gotten this error (error CS0246) and I'm a little confused because I don't see anything wrong with the code? I've had someone else proof check it to make sure it is actually okay, but he can't see an error either. Are be both just being stupid?

The error is on this code:

 private void SetupVitalModifiers() {
         //health
         ModifyingAttribute healthModifier = new ModifyingAttribute();
         healthModifier.attribute = GetPrimaryAttribute((int)AttributeName.Constitution);
         healthModifier.ratio = .5f;
         
         GetVital((int)VitalName.Health).AddModifier(healthModifier);
         //energy
         ModifyingAttribute energyModifier = new ModifyingAttribute();
         energyModifier.attribute = GetPrimaryAttribute((int)AttributeName.Constitution);
         energyModifier.ratio = .5f;
         
         GetVital((int)VitalName.Energy).AddModifier(energyModifier);
         //mana
         ModifyingAttribute manaModifier = new ModifyingAttribute();
         manaModifier.attribute = GetPrimaryAttribute((int)AttributeName.Willpower);
         manaModifier.ratio = .5f;
         
         GetVital((int)VitalName.Mana).AddModifier(manaModifier);
     }

Here's the full code:

 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];
     }
         
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
     
     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 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 healthModifier = new ModifyingAttribute();
         healthModifier.attribute = GetPrimaryAttribute((int)AttributeName.Constitution);
         healthModifier.ratio = .5f;
         
         GetVital((int)VitalName.Health).AddModifier(healthModifier);
         //energy
         ModifyingAttribute energyModifier = new ModifyingAttribute();
         energyModifier.attribute = GetPrimaryAttribute((int)AttributeName.Constitution);
         energyModifier.ratio = .5f;
         
         GetVital((int)VitalName.Energy).AddModifier(energyModifier);
         //mana
         ModifyingAttribute manaModifier = new ModifyingAttribute();
         manaModifier.attribute = GetPrimaryAttribute((int)AttributeName.Willpower);
         manaModifier.ratio = .5f;
         
         GetVital((int)VitalName.Mana).AddModifier(manaModifier);
     }
     private void SetupSkillModifiers() {
     }
 }

And here is the code to where BaseCharacter.cs is relating to:

 using System.Collections.Generic;
 
 public class ModifiedStat : BaseStat {
     private List<ModifyingAttribute> _mods;            //A list of Attributes that modify this stat
     private int _modValue;                            //The amount added to the baseValue from the modifiers
     
     public ModifiedStat() {
         _mods = new List<ModifyingAttribute>();
         _modValue = 0;
     }
     
     public void AddModifier( ModifyingAttribute mod) {
         _mods.Add (mod);
     }
     
     private void CalculateModValue() {
         _modValue = 0;
         
         if(_mods.Count > 0)
             foreach(ModifyingAttribute att in _mods)
                 _modValue += (int)(att.attribute.AdjustedBaseValue * att.ratio);
     }
     
     public new int AdjustedBaseValue{
                 get { return BaseValue + BuffValue + _modValue; }
     }
 
 public struct ModifyingAttribute {
     public Attribute attribute;
     public float ratio;
     }
 }


Thanks in advance!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Dave-Carlile · May 02, 2013 at 01:59 PM

You've defined the ModifyingAttribute struct inside the ModifiedStat class, so in order to reference it you need to qualify it with the class it's defined in, i.e...

 ModifiedStat.ModifyingAttribute healthModifier = new ModifiedStat.ModifyingAttribute();

Or you can move the struct definition outside of the class.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image suicidalcrow · May 02, 2013 at 02:13 PM 0
Share

Oh wow, yes! Thank you very much! It just completely threw me off course and confused me! Thanks, again! (:

avatar image
0

Answer by Jessy · May 02, 2013 at 01:58 PM

Only ModifiedStat can use ModifyingAttribute directly. Otherwise, you need to tell the compiler where to find it.

ModifiedStat.ModifyingAttribute

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

14 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Project structure, finding scripts vis GetComponent and related errors 1 Answer

error CS0246: The type or namespace name `List' could not be found. 1 Answer

What does "The type or namespace name x could not be found" mean? 5 Answers

UnityEngine could not be found? 7 Answers

error CS0246: The type or namespace name `rect' could not be found. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges