点击游戏对象后显示游戏对象

问题描述 投票:0回答:1

我正在统一开发Android游戏我有一个问题,我有多维数据集1,多维数据集2和多维数据集3,而且我还有按钮1,按钮2,按钮3我想要当我单击多维数据集1按钮1显示当我单击多维数据集2按钮2显示按钮1隐藏当我单击多维数据集3按钮3显示按钮2隐藏我能做什么

private void Update()
{

    if (Input.GetMouseButtonDown(0))
    {

    }
    RaycastHit hit;
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit, 100.0f))
        {
            if (hit.transform != null)
            {

                PrintName(hit.transform.gameObject);

        }


    }
}

private void PrintName(GameObject go)
{

    print(go.name);

}

此代码仅打印了我尝试更改其功能的游戏对象的名称,但不起作用

c# android unity3d click
1个回答
1
投票

您可以做的一个例子是:


public Button button1, button2, button3;

private void PrintName(GameObject cube) {
   print(cube.name);
    if(cube.name.Equals("cube1") {
        button1.gameObject.SetActive(true);
        button2.gameObject.SetActive(false);
        button3.gameObject.SetActive(false);
    }
    if(cube.name.Equals("cube2") {
        button1.gameObject.SetActive(false);
        button2.gameObject.SetActive(true);
        button3.gameObject.SetActive(false);
    }
    if(cube.name.Equals("cube3") {
        button1.gameObject.SetActive(false);
        button2.gameObject.SetActive(false);
        button3.gameObject.SetActive(true);
    }
}

您需要所有按钮作为其属性。这些按钮只是默认的ui统一按钮。

© www.soinside.com 2019 - 2024. All rights reserved.