Написал код создаются 64 объекта я их сохраняю в один двоичный массив
[SerializeField] public GameObject[,] plitkmac = new GameObject [8, 8];
.
.
plitkmac[y,x]=inst;
Они все сохраняются и я могу пользоваться массивом в одном скрипте. Но мне необходимо использовать эго и в других скрипта.
Пробовал данным способом:
GameObject[,] plitkmac = transform.GetComponent<creature>().plitkmac;
print(plitkmac[1,1].name);
Но юнити выдает ошибку а visual studio нет.
NullReferenceException: Object reference not set to an instance of an object
panel.cretecreateСhecker () (at Assets/Board/scripts/panel.cs:15)
panel.Start () (at Assets/Board/scripts/panel.cs:10)
весь код
using System;
using UnityEngine;
using UnityEngine.UI;
public class creature : MonoBehaviour
{
public GameObject instpref;
[SerializeField] public GameObject[,] plitkmac = new GameObject[8, 8];
void Start()
{
int plas = 0;
for (int y=0; y< 8; y++ )
{
int gpy = -315 + y * 90;
for (int x=0; x<8; x++)
{
int gpx = -315 + x * 90;
GameObject inst = Instantiate(instpref, transform);
int collor = ((8 * y + x+plas)%2);
if (collor == 1)
{
inst.GetComponent<Image>().color = Color.white;
}
inst.GetComponent<RectTransform>().anchoredPosition =new Vector2(gpx, gpy);
plitkmac[y ,x] = inst;
inst.name = "panel" + y + x;
}
plas++;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class panel : MonoBehaviour
{
void Start()
{
cretecreateСhecker();
}
public void cretecreateСhecker()
{
GameObject[,] plitkmac = transform.GetComponent<creature>().plitkmac;
print(plitkmac[1,1].name);
}
и еще вопрос мoжно ли сделать двоичный массив видным в инспекторе и если да то как?