- Home /
dealing with gameObject formations
I'm building a game that is very much like chess. The GameObject that i would like to track is a prefab that i have created called Square. The board is made up of 10 by 10 of these squares. These Squares come in 3 forms which can be switched from water, grass, or to mountain. All squares are grass at the start. The player must place the all of the water and mountain tiles. There are 7 each. I have no problem tracking these and dealing with them when they change. My question is what is the best way to go about tracking the locations of these squares and what shapes are created so that i can prevent some invalid formations. For example the player should not be allowed to create an enclosed area using mountains. Should i create a multidimensional array to keep track of what each square is. even thou its already stored in that class? I would like to prevent the user form To prevent it from creating an invalid formation. Sorry This is so long winded. I'm not sure it will even be clear what im asking without explaining more. Which I will be happy to if asked. Thanks!
Answer by aldonaletto · Aug 04, 2011 at 04:20 AM
If I was to make a game like this, I would use a 10x10 integer array. It's much easier and faster to analyze an integer array than 100 game objects. Each element in this array must be associated to its square by two indexes, row and col, stored in the square script. Any time the player is about to modify a square, analyze the array and determine which types are available for this square, and if it's modified update the array element.
There's no need to manually set each row and col: have an empty object at the 0,0 square center, and child all squares to it, then in the square Start() calculate the indexes based on squareWidth:
var row: int; var col: int;
function Start(){ row = Mathf.RoundToInt(transform.localPosition.z / squareWidth); col = Mathf.RoundToInt(transform.localPosition.x / squareWidth); ...
Your answer
Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
FPS keep a loadout 0 Answers
Distribute terrain in zones 3 Answers