好的,所以我不确定确切发生了什么,我一直在寻找其他标题相同/相似的帖子,但是他们都不清楚我在做什么,我有一个公共GameObject到另一个对象,我试图从变量GameObjects组件(脚本)向数组添加变量,但是它一直给我这个错误,这是我的代码。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Dice : MonoBehaviour
{
public int diceNumber = 0;
public bool diceActive = true;
public GameObject rollbar;
// Start is called before the first frame update
void Start()
{
onCreate();
}
// Update is called once per frame
void Update()
{
}
//Run this when the object is either created or activated (Basically when the dice becomes interactable)
void onCreate()
{
//Insert the dice into the array
rollbar.GetComponent<RollButton>().basicDice.Insert(diceNumber, gameObject);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RollButton : MonoBehaviour
{
int NumberOfDice = 0;
public ArrayList basicDice;
// Start is called before the first frame update
void Start()
{
basicDice = new ArrayList();
}
// Update is called once per frame
void Update()
{
}
//Custom Function to roll the dice
public void roll()
{
print(basicDice);
}
}