Quantcast
Viewing all articles
Browse latest Browse all 2891

error CS0201 (2d roguelike)

"Assets/Scripts/BoardManager.cs(65,26): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement" That error redirects me to line 65: ( gridPositions.RemoveAt [randomIndex];) But I can not find the error. All code below: using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using Random = UnityEngine.Random; public class BoardManager : MonoBehaviour { [Serializable] public class Count{ public int minimum; public int maximum; public Count(int min, int max) { // construct minimum = min; maximum = max; } } public int columns = 8; public int rows = 8; public Count wallCount = new Count(5,9); public Count foodCount = new Count(1,5); public GameObject exit; public GameObject[] floorTiles; public GameObject[] wallTiles; public GameObject[] enemyTiles; public GameObject[] foodTiles; public GameObject[] outerWallTiles; private Transform boardHolder; private List gridPositions = new List (); void initialiseList(){ gridPositions.Clear(); for (int i = 1; i < columns - 1; i++) { for (int j = 1; j < rows -1; j++){ gridPositions.Add (new Vector3 (i, j, 0f)); } } } void boardSetup(){ // to set outerWall and floor of the game boardHolder = new GameObject ("Board").transform; for (int x = -1; x < columns + 1; x++) { for (int y = -1; y < rows + 1; y++) { GameObject toInstantiate = floorTiles [Random.Range (0, floorTiles.Length)]; // instantiate random floor tiles in the range if (x == -1 || x == columns || y == -1 || y == rows) { toInstantiate = outerWallTiles [Random.Range (0, outerWallTiles.Length)]; // to instantiate random outer wall tiles in the range GameObject instance = Instantiate (toInstantiate, new Vector3 (x, y, 0f), Quaternion.identity) as GameObject; instance.transform.SetParent (boardHolder); } } } } Vector3 RandomPosition(){ int randomIndex = Random.Range (0, gridPositions.Count); Vector3 randomPosition = gridPositions [randomIndex]; gridPositions.RemoveAt [randomIndex]; return randomPosition; } void layoutObjectAtRandom(GameObject[] tileArray, int minimum, int maximum){ // spawn the titles randomly int objectCount = Random.Range(minimum, maximum + 1); // para decidir quantas paredes por exemplo terá no nivel for (int x = 0; x < objectCount; x++) { Vector3 randomPosition = RandomPosition (); GameObject tileChoice = tileArray[Random.Range(0,tileArray.Length)]; Instantiate (tileChoice, randomPosition, Quaternion.identity); } } public void setupScene(int level){ boardSetup (); initialiseList (); layoutObjectAtRandom (wallTiles, wallCount.minimum, wallCount.maximum); layoutObjectAtRandom (foodTiles, foodCount.minimum, foodCount.maximum); int enemyCount = (int)Mathf.Log (level, 2f); layoutObjectAtRandom (enemyTiles, enemyCount, enemyCount); Instantiate (exit, new Vector3 (columns - 1, rows - 1, 0f), Quaternion.identity); } }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



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