Untitled
unknown
plain_text
2 years ago
1.9 kB
8
Indexable
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class Math : MonoBehaviour
{
public TextMeshProUGUI op1;
public TextMeshProUGUI op2;
public TextMeshProUGUI operand;
public TextMeshProUGUI answer1;
public TextMeshProUGUI answer2;
public TextMeshProUGUI answer3;
//public TextMeshProUGUI op3;
private int opt1;
private int opt2;
int correct;
private int otherFlag;
private int otherFlag2;
private TextMeshProUGUI [] shuffleFlag;
private int [] answers;
void Shuffle<int>(ref List<int> list)
{
int n = list.Count;
while (n > 1)
{
n--;
int k = Random.Range(0, n + 1);
int value = list[k];
list[k] = list[n];
list[n] = value;
}
}
// Start is called before the first frame update
void Start()
{
opt1 = Random.Range(-50, 51);
opt2 = Random.Range(-50, 51);
correct = opt1 + opt2;
otherFlag = Random.Range(correct - 10, correct + 10);
otherFlag2 = Random.Range(correct - 10, correct + 10);
shuffleFlag = new TextMeshProUGUI[answer1, answer2, answer3];
answers = new int [otherFlag, correct, otherFlag2];
}
// Update is called once per frame
void Update()
{
//string load = "What is" + opt1.ToString() + "+" op2.ToString();
op1.text = opt1.ToString();
op2.text = opt2.ToString();
operand.text = "+";
Shuffle(ref answers);
for (int i = 0; i < 3; i++){
shuffleFlag[i].text = answers[i].ToString();
}
shuffleFlag[0].color = Color.green;
shuffleFlag[1].color = Color.blue;
shuffleFlag[2].color = Color.magenta;
}
}
Editor is loading...
Leave a Comment