Answer the question
In order to leave comments, you need to log in
How to use one binary array in multiple unity scripts?
I wrote the code, 64 objects are created, I save them in one binary array
[SerializeField] public GameObject[,] plitkmac = new GameObject [8, 8];
.
.
plitkmac[y,x]=inst;
GameObject[,] plitkmac = transform.GetComponent<creature>().plitkmac;
print(plitkmac[1,1].name);
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);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question