I am making a card game called Kugelblitz and with it right now I am making the winning goal with six sets of numbers matching a pattern but not specific numbers and the cards to not have to fit a certain set. . I am wondering if you can make a vriable if statement that can fit this well: this is an example for one.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ColorHarmony : MonoBehaviour {
[Range(1, 6)]
[SerializeField] int firstNumber = 1;
[Range(1, 6)]
[SerializeField] int secondNumber = 1;
[Range(1, 6)]
[SerializeField] int thirdNumber = 1;
[Range(1, 6)]
[SerializeField] int forthNumber = 1;
[Range(1, 6)]
[SerializeField] int fifthNumber = 1;
[Range(1, 6)]
[SerializeField] int sixthNumber = 1;
void Update () {
NumberLimiter();
MatchingNumbers();
}
void NumberLimiter() {
if (firstNumber <= 0) {
firstNumber = firstNumber + 6;
}
else if (firstNumber >= 7) {
firstNumber = firstNumber - 6;
}
else {
return;
}
}
void MatchingNumbers() {
/*first to sixthNumber can replace any of these numbers*/
if (firstNumber == i && secondNumber == i && thirdNumber == i &&
forthNumber == i + 1 && fifthNumber == i + 3 && sixthNumber == i + 5) {
Debug.Log("You Win!");
}
}
)
And this is an example of what I started doing but there is a lot of repitition and if one thing is wrong than my code will break.
/*This version will just go through all hard number sets of if statements instead of one that will
*can do it all on its own.*/
void MatchingNumbers() {
if (firstNumber == 1 && secondNumber == 1 && thirdNumber == 1 &&
forthNumber == 2 && fifthNumber == 4 && sixthNumber == 6) {
Debug.Log("You Win!");
}
else if (firstNumber == 2 && secondNumber == 2 && thirdNumber == 2 &&
forthNumber == 3 && fifthNumber == 5 && sixthNumber == 1) {
Debug.Log("You Win!");
}
}