I get the error above from the script below, I sort of understand the problem, basically it won’t let me assign a GameObject to a variable that’s an array/table. What I don’t understand is why I’m getting the error, somewhere in there it should get converted shouldn’t it? I literally copied and pasted the code from this page:
And then I changed the names on the variables and the tag so it actually fits in with my stuff.
Help please. Thank you.
Alternatively if there’s another way to compose a table/list/array (I don’t really know what it’s properly called in C# in Unity), I could do that. my end goal is to have the list called voxels
to contain every GameObject with the tag “TerrainVoxel”.
using UnityEngine;
using System.Collections;
public class SkyAir : MonoBehaviour {
public GameObject Air;
public GameObject VoxelTerrain;
public Object voxels;
// Use this for initialization
void Start () {
if (voxels == null)
voxels = GameObject.FindGameObjectsWithTag("TerrainVoxel");
foreach (Object voxel in voxels) {
if (voxel.transform.position.y >= 513) {
Instantiate (Air, voxel.transform.position, voxel.transform.rotation);
Destroy (voxel);
}
}
}
// Update is called once per frame
void Update () {
}
}