• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by swartak · May 28, 2014 at 08:22 PM · integerboardgamearray list

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> (); } } }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is there a setting to change integer rounding to 'Swedish Rounding'? 2 Answers

Problem displaying an int 1 Answer

Using Time.deltaTime when incrementing a value 1 Answer

Change Integer to All Gameobjects With Script 1 Answer

Creating a Playerpref score system 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges