pls help i can’t make the game accept the “public” part of this line of the code “public Tile GetTileAt(int x,int y,int z)” and if i delete the public , i get like 6 other errors witch i tried solve and still couldn’t get it to work
the code is from a tutorial on base building games:/
this is the error if i leave the public on :
Assets\models\World.cs(27,2): error CS0106: The modifier ‘public’ is not valid for this item
and this is the error i get if i don’t leave it : Assets\models\World.cs(17,10): error CS0029: Cannot implicitly convert type ‘Tile[,,]’ to 'Tile[,*]’
Assets\models\World.cs(22,2): error CS0022: Wrong number of indices inside [ ]; expected 2
Assets\models\World.cs(22,18): error CS0029: Cannot implicitly convert type ‘World’ to ‘int’
Assets\models\World.cs(32,11): error CS0022: Wrong number of indices inside [ ]; expected 2
Assets\models\World.cs(27,7): warning CS8321: The local function ‘GetTileAt’ is declared but never used
Assets\models\Tile.cs(7,11): warning CS0414: The field ‘Tile.type’ is assigned but its value is never used
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class World {
Tile[,] tiles;
int width;
int length;
int height;
public World(int width = 5 , int length = 5 , int height = 1) {
this.width = width;
this.length = length;
this.height = height;
tiles = new Tile[width,length,height];
for (int x = 0; x <width; x++) {
for (int y = 0; y <length; y++) {
for (int z = 0; z <height; z++) {
tiles [x,y,z] = new Tile[this, x , y , z];
}
}
}
public Tile GetTileAt(int x,int y,int z) {
if (x > width || x<0 || y > length || y<0 || z > height || z<0) {
Debug.LogError("Tile ("+x+","+y+","+z+") is out of range.");
return null;
}
return tiles [x,y,z];
}
}
}