Question by
BrentonStumpf · Nov 01, 2018 at 09:45 PM ·
c#detectionsortingpattern
How to sort and detect pattern?
I have a pattern I want people to recreate the pattern with color cards. In the code I have the colors cycle from 1 to 6 and anythign lower they will add 6 and andthing higher than 7 will take away by 6. I want to know if there is a way to sort numbers and see if they match the pattern. The one I have is too fixed and I am having trouble making a sort for the numbers. The image shows the pattern and cards on the side show how they are scrambled but do recreate a pattern.
Here is the code I have for the current color on the card that I want to pull into a new script and sort to see if they match.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CurrentColor : MonoBehaviour {
[Header("Colors")]
[SerializeField] Material redColor;
[SerializeField] Material purpleColor;
[SerializeField] Material blueColor;
[SerializeField] Material greenColor;
[SerializeField] Material yellowColor;
[SerializeField] Material orangeColor;
[Range(1, 6)]
[SerializeField] public int currentColorstate = 1;
private void Update() {
ChosenColor();
}
public void ChosenColor() {
if (currentColorstate <= 0) {
currentColorstate = currentColorstate + 6;
}
else if (currentColorstate == 1) { //red
GetComponent<Image>().material = redColor;
}
else if (currentColorstate == 2) { //purple
GetComponent<Image>().material = purpleColor;
}
else if (currentColorstate == 3) { //blue
GetComponent<Image>().material = blueColor;
}
else if (currentColorstate == 4) { //green
GetComponent<Image>().material = greenColor;
}
else if (currentColorstate == 5) { //yellow
GetComponent<Image>().material = yellowColor;
}
else if (currentColorstate == 6) { //orange
GetComponent<Image>().material = orangeColor;
}
else if (currentColorstate >= 7) {
currentColorstate = currentColorstate - 6;
}
else {
Debug.LogError("Broken color");
}
}
}
And Another picture of it in play
Comment