Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Script error

Discussion in 'Scripting' started by Paykoman, Nov 29, 2014.

  1. Paykoman

    Paykoman

    Joined:
    Jun 26, 2014
    Posts:
    500
    Hi guys im writing a script for a consumable class and im getting a erro that i dont understand can anyone halp me?

    in line 5 and 15 of my code i go this error:

    CS0246: the type of namepsace name 'Vital' could not be found. Are u missing a using directive or and assembly reference?

    Wt am i doing wrong here?
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Consumables : BuffItem
    4. {
    5.     private Vital[] _vital;            //a list of vitals to heal
    6.     private int[] _amountToHeal;        //the amount of the heal
    7.  
    8.     private float _buffTime;            //the long the buff losts if there is one
    9.  
    10.     public Consumables()
    11.     {
    12.         Reset ();
    13.     }
    14.  
    15.     public Consumables(Vital[] v, int[] a, float b)
    16.     {
    17.         _vital = v;
    18.         _amountToHeal = a;
    19.         _buffTime = b;
    20.     }
    21.  
    22.     public void Reset()
    23.     {
    24.         _buffTime = 0;
    25.  
    26.         for (int cnt = 0; cnt < _vital.Length; cnt++)
    27.         {
    28.             _vital [cnt] = new VitalClass();
    29.             _amountToHeal[cnt] = 0;
    30.         }
    31.     }
    32.  
    33.     public int VitalCount()
    34.     {
    35.         return _vital.Length;
    36.     }
    37.  
    38.     public VitalClass VitalAtIndex(int index)
    39.     {
    40.         if (index < _vital.Length + 1 && index > -1)
    41.             return _vital [index];
    42.         else
    43.             return new VitalClass();
    44.     }
    45.  
    46.     public int HealAtIndex(int index)
    47.     {
    48.         if (index < _amountToHeal.Length + 1 && index > -1)
    49.             return _amountToHeal [index];
    50.         else
    51.             return 0;
    52.     }
    53.  
    54.     public void SetVitalAt(int index, VitalClass vital)
    55.     {
    56.         if (index < _amountToHeal.Length + 1 && index > -1)
    57.             _vital [index] = vital;
    58.     }
    59.  
    60.     public void SetHealAt(int index, int heal)
    61.     {
    62.         if (index <_amountToHeal.Length + 1 && index > -1)
    63.             _amountToHeal [index] = heal;
    64.     }
    65.  
    66.     public void SetVitalAndHealAt(int index, VitalClass vital, int heal)
    67.     {
    68.         SetVitalAt (index, vital);
    69.         SetHealAt (index, heal);
    70.     }
    71.  
    72.     public float buffTimer
    73.     {
    74.         get{ return _buffTime;}
    75.         set{ _buffTime = value;}
    76.     }
    77. }
    78.  
    79.  
     
  2. fox4snce

    fox4snce

    Joined:
    Jan 25, 2014
    Posts:
    74
    Where do you declare what a "Vital" is? You are trying to create an array of "Vital"s... but the compiler doesn't know what that is.
     
    Paykoman likes this.
  3. Paykoman

    Paykoman

    Joined:
    Jun 26, 2014
    Posts:
    500
    i think i already know wt is miss know that u said tgis.. i probably need call it vitalclass[] and not vital[] since this came from my vitalclass script.. i will try fix this when im home ty m8.
     
  4. Paykoman

    Paykoman

    Joined:
    Jun 26, 2014
    Posts:
    500
    Yes is exactly that.. ty anyway for ur time. Appreciate