You are setting the object as cubeObject2 in Start() and then in Disable and Enable setting active cubeObject without the number. It should be the same (also, you declare the name as cube object before Start() so don’t forget to change that one if needed).
UnassignedReferenceException: The variable cubeObject of BlockViewer has not been assigned.
You probably need to assign the cubeObject variable of the BlockViewer script in the inspector.
BlockViewer.Enable () (at Assets/Scene/Scripts/BlockViewer.cs:22)
I wasn’t attaching it to the empty game object, but I did now, and it works all the same.
Your error seems to be changed, also the script name is different? Maybe I will try showing you how it looks in my code, as I need to leave the house now. Or maybe someone else could help you better.
The class you wrote is called BlockViewer, but the exception says you’re using the TagDisabler class. So you’re actually calling an Enable() method from another class.
If you’re doing it via a button, you need to assign to it the right game object (the one with the BlockViewer script), and then choose the BlockViewer.Disable (or Enable) method.
If your goal is to disable/enable ALL objects with a specific tag, you just have to write the class this way:
[code]using System.Collections;
using UnityEngine;
public class CubeEnable : MonoBehaviour {
private GameObject[] cubeList;
void Start(){
cubeList = GameObject.FindGameObjectsWithTag("Cube");
}
public void Disable(){
foreach(GameObject obj in cubeList){
obj.SetActive(false);
}
}
public void Enable(){
foreach(GameObject obj in cubeList){
obj.SetActive(true);
}
}
}[/code]
However, I’d strongly advice that you follow some course about OOP, you’re lacking so far (based on your last 2-3 help requests on the forum) basic understanding of how to code and how OOP works. Take a break from Unity and do that, it’ll prove very useful.