Alright, so im not sure exactly whats going on, i have been searching around other posts with the same/similar titles, but none of them are clear on whats wrong with what im doing, i have a public GameObject that i set to another object, im trying to add a variable into an array from the variables GameObjects component (script) but it keeps giving me this error, here is my code.
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);
}
}
Edit:
Screenshot of inspector and rollbutton script
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);
}
}