Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

CS2021 Error - Unclear on Why

$
0
0
I'm trying to figure out what I'm doing wrong, and keep getting weird errors that don't make sense to me, but I think I've got it narrowed down. Probably self-explanatory to veterans, this script should grab the array of tiles I drop in the inspector, fill a numeric array with a random number between 0 and (tileStyles), then use those numbers to choose an entry in tiles[] to put on the screen at x,y. (It's very likely there's stuff I don't need, as I'm cribbing from two of the tutorials, so input is welcome.) I received error CS0201, "Only assignment, call..." etc. and it indicates the last real line of code with Instantiate. using UnityEngine; using System; using System.Collections.Generic; using Random = UnityEngine.Random; [Serializable] public class MakeMap : MonoBehaviour { public int cols; public int rows; public int tileStiles = 6; public int[,] gridMap; public GameObject[] tiles; private int temp; void Start() { gridMap = new int[cols,rows]; LoadMap(); ShowMap(); } void LoadMap() { //loop to fill a grid with tile numbers for (int x = 0; x < cols; x++) { for (int y = 0; y < rows; y++) { gridMap[x,y] = (Random.Range(0,tileStiles)); } } } void ShowMap() { //Loop to select a tile from the list, as the coordinates from gridMap, and instantiate for (int x = 0; x < cols; x++) { for (int y = 0; y < rows; y++) { GameObject toInstantiate = tiles[gridMap[x,y]]; //The value should identify which of the tiles to put onscreen Instantiate (toInstantiate, new Vector3 (x, y, 0f), Quaternion.identity) as GameObject; } } } } Thanks in advance! (Edited for clarity)

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>