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

How do I solve my Match 3 Game coding error?,

$
0
0
I am working on a Match 3 game by following a Unity tutorial step by step on this web page: (https://www.raywenderlich.com/673-how-to-make-a-match-3-game-in-unity) I am currently at the step where I put in lines of code that make it so that the sprites don't spawn in groups of 3 or more when the game starts. Here's what I have so far: using UnityEngine; using System.Collections; using System.Collections.Generic; public class BoardManager : MonoBehaviour { public static BoardManager instance; public List characters = new List(); public GameObject tile; public int xSize, ySize; private GameObject[,] tiles; public bool IsShifting { get; set; } void Start () { instance = GetComponent(); Vector2 offset = tile.GetComponent().bounds.size; CreateBoard(offset.x, offset.y); Sprite[] previousLeft = new Sprite[ySize]; Sprite previousBelow = null; } private void CreateBoard (float xOffset, float yOffset) { tiles = new GameObject[xSize, ySize]; float startX = transform.position.x; float startY = transform.position.y; for (int x = 0; x < xSize; x++) { for (int y = 0; y < ySize; y++) { GameObject newTile = Instantiate(tile, new Vector3(startX + (xOffset * x), startY + (yOffset * y), 0), tile.transform.rotation); tiles[x, y] = newTile; **newTile.transform.parent = transform; // 1 List possibleCharacters = new List(); // 1 possibleCharacters.AddRange(characters); // 2 possibleCharacters.Remove(previousLeft[y]); // 3 Sprite previousBelow = null; possibleCharacters.Remove(previousBelow); Sprite newSprite = possibleCharacters[Random.Range(0, possibleCharacters.Count)]; newTile.GetComponent().sprite = newSprite; // 3 previousLeft[y] = newSprite; previousBelow = newSprite;** } } } } I don't understand these steps: 1. Create a list of possible characters for this sprite. 2. Add all characters to the list. 3. Remove the characters that are on the left and below the current sprite from the list of possible characters. I don't use C# often, so I'm not that familiar with it. I would really appreciate it if someone were to help me.

Viewing all articles
Browse latest Browse all 2891

Trending Articles



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