- Home /
May I have help figuring out to code a WIN based on the Y-axis rotation of multiple gameobjects at once?
I have a project for school that's due in two days, this is literally my first game that I'm trying to finish. I have replicated the classic game "Lights Out"
I have finally finished the logic/math on making the correct cubes(lights) rotate on or off based on what light the player clicks. My only problem is I'm stuck trying to figure out how to go about setting the win condition i.e all lights are toggled off.
I'm using instantiation to make 25(5x5) cubes. On or Off is dictated by them rotating 45 degrees on the y-axis. If all of them get turned off, then the game is complete.
Im very new to coding, but I was trying to do something like:
if(all gameobjects/cubes are 45 degrees on the y-axis){
lights aren't active anymore
you win }
I'm open to any suggestions on how to most efficiently do this.
Answer by xxmariofer · Jan 18, 2019 at 07:42 PM
the lights already turn off when you clicked them? if not you can set the light component intensity to 0 when the player clicks then, just create one script with a list with all 25 lights, you can have a method call something like onclick in which you rotate the lamp turn in off and iterate the list of ligjts untill you find one thats turn in on. there are different ways of doing like each light having a property called On or something like that for saving some time not having to compare lights intensitys thats just up to you.
I should have been more specific, I apologize. There aren't actual lights per se. The cubes represent lights. When the cubes are 45degrees, they are "on", when they are 0 on the y-axis, they are "off".
When the player clicks on a cube, it turns on(or off) each neighbor and the cube above and below it. It's a puzzle game where you have to figure out how to turn all of the lights off. I'm trying to figure out how to code the logic of a win, which is all the lights are turned off i.e all of the cubes are 0 on the y-axis.
So essentially I'm trying to say if(all cubes are 0 on the y-axis { you win}
oh ok i didnt know the game, probably there are some algorithms there for doing the checks faster, code:
bool Compare(int width, int height)
{
bool winColumn = true, winRow = true;
for(int column = 0; column < $$anonymous$$AX_COLU$$anonymous$$N; column++)
{
if(!cube[column, height].IsOn) //or check rotation or whatever you want
{
winColumn = false;
}
}
for (int row = 0; row < $$anonymous$$AX_ROW; row++)
{
if (!cube[row, height].IsOn) //or check rotation or whatever you want
{
winRow = false;
}
}
if(!winRow && !winColumn)
{
Debug.Log("NO WIN FOR YOU");
return false;
}
else
{
Debug.Log("CONGRATS");
return true;
}
}
cube is the array with all cubes and maxrow and maxcolum the number of rows and columns
Your answer