【发布时间】:2019-12-05 10:29:12
【问题描述】:
Scene view我需要一些帮助来制作 Hololens 的简单原型。
我在移动键盘等场景中有 9 个 UI 附近的交互可触摸按钮。我希望他们随机地一一突出显示。我将按下突出显示的按钮,下一个随机按钮应突出显示,依此类推。我已经成功地为 VR 制作了相同类型的应用程序,但在 MRTK 中,很难突出显示按钮。如果有人帮助我提供示例代码,我将非常感激。
我还附上了我的场景视图。 我已使用以下代码突出显示 VR 中的代码,但我如何在 MRTK 中使用该代码。它不工作。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Diagnostics;
using UnityEngine.UI;
public class Randomcolor : MonoBehaviour
{
public static GameObject B1, B2, B3, B4, B5, B6, B7, B8, B9, BX, ST;
public static int r, r_prev;
void Start()
{
B1 = GameObject.Find("Button1");
B2 = GameObject.Find("Button2");
B3 = GameObject.Find("Button3");
B4 = GameObject.Find("Button4");
B5 = GameObject.Find("Button5");
B6 = GameObject.Find("Button6");
B7 = GameObject.Find("Button7");
B8 = GameObject.Find("Button8");
B9 = GameObject.Find("Button9");
ST = GameObject.Find("ButtonSRT");
B1.GetComponent<Button>().interactable = true;
B2.GetComponent<Button>().interactable = true;
B3.GetComponent<Button>().interactable = true;
B4.GetComponent<Button>().interactable = true;
B5.GetComponent<Button>().interactable = true;
B6.GetComponent<Button>().interactable = true;
B7.GetComponent<Button>().interactable = true;
B8.GetComponent<Button>().interactable = true;
B9.GetComponent<Button>().interactable = true;
}
public void clickB1()
{
Color_Highlight();
}
public void Color_Highlight()
{
System.Random random_number = new System.Random();
r = random_number.Next(9) + 1;
while (r == r_prev)
{
r = random_number.Next(9) + 1;
}
r_prev = r;
if (r == 1) { BX = B1; }
if (r == 2) { BX = B2; }
if (r == 3) { BX = B3; }
if (r == 4) { BX = B4; }
if (r == 5) { BX = B5; }
if (r == 6) { BX = B6; }
if (r == 7) { BX = B7; }
if (r == 8) { BX = B8; }
if (r == 9) { BX = B9; }
var colors = BX.GetComponent<Button>().colors;
colors.normalColor = Color.cyan;
BX.GetComponent<Button>().colors = colors;
}
public void Color_Reset()
{
var colors = BX.GetComponent<Button>().colors;
colors.normalColor = new Color32(69, 154, 43, 255);
BX.GetComponent<Button>().colors = colors;
}
}
【问题讨论】: