Я новичок в C # и Arcore.У меня есть пример сценария контроллера под названием GUIController.cs и другой список вызова элемента ItemScrollList.cs.Я сделал игровой объект с массивами в GUIController с 2 prefabs element 0 и 1. Я пытаюсь добиться того, чтобы каждый раз, когда я нажимал на содержимое itemscrollList (в данном случае 2 элемента, это item1 и item2), мне нужно изменитьсборный на GUIController.
Ошибки, которые я получаю из приведенных ниже кодов, - каждый раз, когда я нажимаю на элемент контента 1 или 2, они возвращают nullpointerexceptions.
Строка в GUIController.cs "AndyPrefab = nowPrefabs.GetComponent (). CurrentPrefabs;"это линия, мне нужно, чтобы правильно показать сборный.Пожалуйста, помогите мне
GUIController.cs
if (hit.Trackable is FeaturePoint)
{
AndyPrefab = AndyPlanePrefab[0];
}
else
{
//this is manual input value AndyPlanePrefab as array 1
//AndyPrefab = AndyPlanePrefab[1];
//this is where i need it to properly show the correct prefab
AndyPrefab = nowPrefabs.GetComponent<ItemScrollList>().currentPrefabs;
}
ItemScrollList.cs
//this is where i create the button for itemlist
private void AddButtons()
{
for (int i = 0; i < itemList.Count; i++)
{
Item item = itemList[i];
GameObject newButton = buttonObjectPool.GetObject();
newButton.transform.SetParent(contentPanel);
ItemButton itemButton = newButton.GetComponent();
itemButton.Setup(item, this);
}
}
//this is where im trying to change the prefabs and connect it to
GUIController, if i click on item 1 it should change the gameobject[] value
to AndyPrefab.
public void TryToChangePrefabs(Item item)
{
if (item == itemList[0]) {
currentPrefabs = changePrefabs.GetComponent().AndyPlanePrefab[0];
Debug.Log("Condition number 1 done");
}
else if (item == itemList[1])
{
currentPrefabs = changePrefabs.GetComponent().AndyPlanePrefab[1];
Debug.Log("Condition number 2 done");
}
}