Hello,
I’ve been working on my first game (a copy of the “Lights Out” game) for the past few weeks and designed the whole thing without looking for strategies. I thought this would be the best way to start learning the language. I’ve finished the game now but would like to review what I’ve done and how I could have done certain aspects better.
I will start by describing the script:
- I have a GameManager script that controls my different scripts and methods.
- It starts by creating a list containing Vector3 values in order to create a grid.
- Next it instantiates background tiles on each coordinate in the list followed by the instantiation of the GreenLights which are also sprites and are given their x and y coordinate as a name so I can later distinguish them.
Then for the click input and the logic:
- A OnMouseDown function returns the name of the GameObject and splits the characters (the x and y value) and sends them as int to the next function.
- The “ClickGrid” function takes the two integers and gives a grid around them using a code like this:
for (i = x-1; i <= x+1; i++){
for (ii = y-1; ii <= y+1; ii++){
if (i>=0 && i<=BoardManager.columns-1 && ii>=0 && ii<=BoardManager.rows-1){
if (GameObject.Find ("Wave"+string.Concat (i,ii)) != null){
- For every tile it brings up it checks the SpriteRenderer component and changes its sprite appropriately.
- As a win detection I am using System.Linq:
public void WinDetection(){
gameObjectArray = GameObject.FindGameObjectsWithTag ("RedLight");
if (gameObjectArray.All (go => go.GetComponent<SpriteRenderer> ().sprite == greenLight)) {
Debug.Log ("You win");
Application.LoadLevel (0);
}
}
Thats it. I would like to hear if I was going in the right direction. I am pretty sure there will be a better way to keep track of all my instantiated objects and would love to hear them. Also I’ve been told before that checking all the sprites as a win detection is very “Gimmicky” and I agree but couldn’t think of a better way (it certainly sometimes does not detect a win situation and sometimes does when it shouldn’t, especially in between click actions).
Thanks in advance if you are taking the time to think about this!