【发布时间】:2021-01-11 08:20:26
【问题描述】:
所以我有一个有 9 个盒子的游戏,有 3 个不同的数字,每个数字在随机位置分布 3 个不同的盒子,每次滚动轮子,都会生成 1 个随机数,打开对应的。例如,如果我滚动 3 号,第 3 号盒子将打开......到目前为止我已经做到了,但现在我被困在如何检测它们是否与我之前打开的盒子匹配(意味着如果我打开 2 个相同的盒子)乘数)
//here is my box class
public class Safe
{
public int multiplier;
public GameObject reward;
}
//and here is my gamemanager class
public class GameManager : MonoBehaviour
{
public Text[] mText;
public GameObject[] openBox;
private int a, b, c;
public Safe[] safe;
// Start is called before the first frame update
void Start()
{
GenerateRandom()
}
// Update is called once per frame
void Update()
{
// this is where i check, e.g if i roll number 5, box 5 will open..
switch (WheelController.finalAngle)
{
case 0:
openBox[0].SetActive(true);
mText[1].gameObject.SetActive(true);
safe[1].reward.gameObject.SetActive(true);
break;
case 40:
openBox[1].SetActive(true);
mText[2].gameObject.SetActive(true);
safe[2].reward.gameObject.SetActive(true);
break;
case 80:
openBox[2].SetActive(true);
mText[3].gameObject.SetActive(true);
safe[3].reward.gameObject.SetActive(true);
break;
case 120:
openBox[3].SetActive(true);
mText[4].gameObject.SetActive(true);
safe[4].reward.gameObject.SetActive(true);
break;
case 160:
openBox[4].SetActive(true);
mText[5].gameObject.SetActive(true);
safe[5].reward.gameObject.SetActive(true);
break;
case 200:
openBox[5].SetActive(true);
mText[6].gameObject.SetActive(true);
safe[6].reward.gameObject.SetActive(true);
break;
case 240:
openBox[6].SetActive(true);
mText[7].gameObject.SetActive(true);
safe[7].reward.gameObject.SetActive(true);
break;
case 280:
openBox[7].SetActive(true);
mText[8].gameObject.SetActive(true);
safe[8].reward.gameObject.SetActive(true);
break;
case 320:
openBox[8].SetActive(true);
mText[0].gameObject.SetActive(true);
safe[0].reward.gameObject.SetActive(true);
break;
}
Matching();
}
void GenerateRandom() //this is where i generate random Array
{
a = Random.Range(15, 21);
b = Random.Range(15, 21);
c = Random.Range(15, 21);
while ((a == b || b == c || a == c))
{
a = Random.Range(15, 21);
b = Random.Range(15, 21);
c = Random.Range(15, 21);
}
for (int i = 0; i < mText.Length; i++)
{
if (i % 3==0)
{
mText[i].text = "x"+ a.ToString();
safe[i].multiplier = a;
}
if (i % 3 == 1)
{
mText[i].text = "x" + b.ToString();
safe[i].multiplier = b;
}
if (i % 3 == 2)
{
mText[i].text = "x" + c.ToString();
safe[i].multiplier = c;
}
}
}
void Matching()
{
// I WANT TO CHECK IF THEY MATCHING AND WIN THE GAME.
}
}
【问题讨论】: