Показать сообщение отдельно
Старый 17.03.2013, 21:52   #984
burovalex
Разработчик
 
Аватар для burovalex
 
Регистрация: 04.04.2012
Сообщений: 468
Написано 37 полезных сообщений
(для 60 пользователей)
Ответ: Фак по Юнити.

Помогите плиз!
Ничего понять не могу, ошибка появляется, а если в инспекторе выбрать ошибочный скрипт прямо в реалтайме - ошибка перестаёт появляться.
NullReferenceException: Object reference not set to an instance of an object

части кода:

public class PlayerController MonoBehaviour {

    private 
Vector3        plantInfoPosition;
    public     
bool         showPlantInfo;
    private 
float        plantInfoEffect;
    public     
GUISkin        plantInfoSkin;
    
    public class 
PlantInfoClass
        
{
        public 
string label;
        public 
float growPercent;
        public 
bool enable;    
        public 
Vector3 position;
        }
        public 
PlantInfoClass plantInfo;
        
        
//[System.Serializable]
        
public class InfoActions {public int type; public float resistanceneedStamina; public string label; public GUITexture icon;}
        public 
InfoActions[] actions;
        public 
int actionsShowCount;
    public 
int actionsCount;


void Start () 
    {
    
plantInfo = new PlantInfoClass();
    
plantInfo.rect = new PlantInfoClass.PlantInfoRect();
        
plantInfo.rect.area = new Rect();
    
plantInfo.color = new PlantInfoClass.PlantInfoColor();
        
plantInfo.color.commentLabel Color.white;
        
plantInfo.color.growIcon Color.white;
        
plantInfo.color.growPercent Color.white;
    
actions = new InfoActions[actionsCount];
}

void Update ()
{
        if (
playerHit.collider.GetComponent<ActionContainer>() != null
            {
            
ActionContainer ac playerHit.collider.GetComponent<ActionContainer>();
            
int len ac.actions.Length;
            
tempInt len;
            for (
int i=0i<leni++)
                {
                
actions[i].type = (int)ac.actions[i].action;    //Error
                
actions[i].resistance ac.actions[i].resistance;      //Error    
                
actions[i].needStamina ac.actions[i].needStamina;    //Error
                //actions[i].label = Database.actionLabel[actions[i].type];  //Error
                
}
            }


Закомментировал ошибочные строки, и ошибка появилась в том месте кода, где обнуляю поля:

for (int i=0i<actionsCounti++) 
  {
actions[i].type 0actions[i].resistance 0factions[i].needStamina 0f;} 
Ошибка та же NullReferenceException: Object reference not set to an instance of an object

Похоже как будто не инициализировал, но
actions = new InfoActions[actionsCount]; 
__________________
(Offline)
 
Ответить с цитированием