Очередная проблема связанна с инициализацией RectTransform
Имеется класс который содержит свойство RectTransform
Синтаксис:
Используется csharp
public class BoardElements:MonoBehaviour
{
public string Name { get; set; }
public RectTransform Position { set; get; }
public Image Images { set; get; }
public BoardProperty boardProterty { get; set; }
public BoardCard boardCard { set; get; }
public BoardPayOnly boardPayOnly { set; get; }
public BoardSingleProperty boardSingleProperty { set; get; }
public BoardElements(string name,string path,BoardProperty boardProterty = null,BoardCard boardCard = null,
BoardPayOnly boardPayOnly = null,BoardSingleProperty boardSingleProperty = null)
{
Name = name;
this.boardCard = boardCard;
this.boardPayOnly = boardPayOnly;
this.boardProterty = boardProterty;
this.boardSingleProperty = boardSingleProperty;
this.Images = GameObject.Find("Board").GetComponent<Image>();
Images.sprite = Resources.Load<Sprite>(path);
Position = new RectTransform();
//ради эксперимента
Position.anchorMax = new Vector2();
Position.anchorMin = new Vector2();
}
}
{
public string Name { get; set; }
public RectTransform Position { set; get; }
public Image Images { set; get; }
public BoardProperty boardProterty { get; set; }
public BoardCard boardCard { set; get; }
public BoardPayOnly boardPayOnly { set; get; }
public BoardSingleProperty boardSingleProperty { set; get; }
public BoardElements(string name,string path,BoardProperty boardProterty = null,BoardCard boardCard = null,
BoardPayOnly boardPayOnly = null,BoardSingleProperty boardSingleProperty = null)
{
Name = name;
this.boardCard = boardCard;
this.boardPayOnly = boardPayOnly;
this.boardProterty = boardProterty;
this.boardSingleProperty = boardSingleProperty;
this.Images = GameObject.Find("Board").GetComponent<Image>();
Images.sprite = Resources.Load<Sprite>(path);
Position = new RectTransform();
//ради эксперимента
Position.anchorMax = new Vector2();
Position.anchorMin = new Vector2();
}
}
В другой классе программы мы инициализируем один объект этого класса
Синтаксис:
Используется csharp
RectTransform tmpTransform = GameObject.Find("Board").GetComponent<RectTransform>();
boardElements[0].Position.anchorMax = new Vector2(tmpTransform.anchorMax.x, tmpTransform.anchorMin.y + 0.1f);
boardElements[0].Position.anchorMin = new Vector2(tmpTransform.anchorMax.x - 0.1f, tmpTransform.anchorMin.y);
И у нас выскакивает нулреференсексепшин
UnityEngine.RectTransform.set_anchorMax (Vector2 value) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/RectTransformBindings.gen.cs:122)
BoardElements..ctor (System.String name, System.String path, .BoardProperty boardProterty, .BoardCard boardCard, .BoardPayOnly boardPayOnly, .BoardSingleProperty boardSingleProperty) (at Assets/Scripts/BasicClass/BoardElements.cs:38)
Что не так??Я уже ради эксперимента и просто в конструкторе присваивал ему Вектор 2 пустой,тогда вылетает там
Помогите пожалуйста разобраться