Помогите плиз!
Ничего понять не могу, ошибка появляется, а если в инспекторе выбрать ошибочный скрипт прямо в реалтайме - ошибка перестаёт появляться.
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 resistance, needStamina; 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=0; i<len; i++)
{
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=0; i<actionsCount; i++)
{actions[i].type = 0; actions[i].resistance = 0f; actions[i].needStamina = 0f;}
Ошибка та же NullReferenceException: Object reference not set to an instance of an object
Похоже как будто не инициализировал, но
actions = new InfoActions[actionsCount];