I've been working on this for so long but unfortunately, I'm not progressing at all. I am creating a personality quiz in Unity wherein each question have choices where in depending on each choice, a certain variable is increasing in value. The quiz seeks to show the user's top 5 best fit patterns (which is the variable with the highest value) based on his personality which will be based upon his answers. The public voids are called depending on which choice/button was clicked through the on click in the inspector.
public class QuizScript : MonoBehaviour {
public int snake = 0;
public int centipede = 0;
public void Q2C1() //question 2 choice 1
{
snake = snake + 1;
Debug.Log("Snake = " + snake); //for me to see if it works
}
public void Q3C1() //question 3 choice 1
{
centipede = centipede + 1;
Debug.Log("Centipede = " + centipede);
}
}
There are 26 patterns in all but in the mean time, I just want to sort two variables which are the snake and the centipede. I have searched for tutorials about sorting variables and there are short and long methods. But either way, I am having a hard time understanding it and applying it in my code. In one method, it is required to use another public static void or static int to do the sorting, but what confuses me is how will I be able to call it inside another public void which will be the one called and done when the button is clicked, which is not possible after trying it in the code. (Also, public static void does not recognize the already declared variables inside the class which is a big problem.) I have thought of calling the static void separately in the on click of the button that can be seen in the inspector but maybe because it is a static void, I cannot find it in the options.
This is the code where I am unable to call static int SortByScore in the inspector.
static int SortByScore(int snake, int centipede)
{
return centipede.CompareTo(snake);
}
Thank you so so much in advance for the help. :)