- Home /
Trouble with array int board game
Hi I'm new to unity and I'm making "monopoly" style board game and I've trying to figure out how to use this array properly for days. What I want is for an event to be triggered after the dice is rolled so that the tile the player needs to go to becomes active. The hard part for me though is setting the value of oldsquare. I have it showing (oldsquare + whatever the play rolled) How would I set the value for oldsquare to the new square?
using UnityEngine; using System.Collections; using System.Collections.Generic; public class PlayerScript : MonoBehaviour { public GuiPanels Numberbox; public int GotoTile = 1; public List<int> TileList; private float distance; public int roll; public int currentSquare; public int numSquaresToMove; public GameObject player1; public GuiPanels count1; public GuiPanels count2; public GuiPanels count3; public GuiPanels count4; public GuiPanels count5; public GuiPanels count6; private GuiPanels rolled; public float totalNumberOfSquares; public int oldsquare; // Use this for initialization void Start () { TileList = new List<int>(); TileList.Add(29); TileList[0] = 0; TileList[1] = 1; TileList[2] = 2; TileList[3] = 3; TileList[4] = 4; TileList[5] = 5; TileList[6] = 6; TileList[7] = 7; TileList[8] = 8; TileList[9] = 9; TileList[10] = 10; TileList[11] = 11; TileList[12] = 11; TileList[13] = 12; TileList[14] = 14; TileList[15] = 15; TileList[16] = 16; TileList[17] = 17; TileList[18] = 18; TileList[19] = 19; TileList[20] = 20; TileList[21] = 21; TileList[22] = 22; TileList[23] = 23; TileList[24] = 24; TileList[25] = 25; TileList[26] = 26; TileList[27] = 27; TileList[28] = 28; TileList[29] = 29; oldsquare = 0; //currentSquare = 0; player1 = GameObject.FindGameObjectWithTag ("Player"); for (int i = 0; i < 30; i++){ if (count1 == true) { currentSquare = TileList[oldsquare + 1]; } if (count2 == true) { currentSquare = TileList[oldsquare + 2]; } if (count3 == true) { currentSquare = TileList[oldsquare + 3]; } if (count4 == true) { currentSquare = TileList[oldsquare + 4]; } if (count5 == true) { currentSquare = TileList[oldsquare + 5]; } if (count6 == true) { currentSquare = TileList[oldsquare + 6]; } // (currentSquare + 1) % 30; } } // Update is called once per frame void Update () { Numberbox = GetComponent<GuiPanels>(); if (Numberbox == true) { count1 = GetComponent<GuiPanels> (); count2 = GetComponent<GuiPanels> (); count3 = GetComponent<GuiPanels> (); count4 = GetComponent<GuiPanels> (); count5 = GetComponent<GuiPanels> (); count6 = GetComponent<GuiPanels> (); rolled = GetComponent<GuiPanels> (); } } }
Your answer
Follow this Question
Related Questions
Need help with basic magic system 0 Answers
if statements is not working properly 1 Answer
if statement for 6 ints help C# 2 Answers
How do I increase an integer?? 3 Answers
How do I get my project to sense when an integer has gone up by a certain amount? 2 Answers