如果激活另一个按钮,则激活按钮

时间:2018-03-22 15:30:50

标签: c# unity3d uibutton

所以我想激活一个按钮只有当其他多个按钮被激活时,在这种情况下那些多个按钮都是Button1,所以当它被激活时,它也应该激活按钮readyToRun

using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when Using UI elements.

public class GratzScript : MonoBehaviour
{        
    public Button Button1;
    public Button readyToRun;

    public void Update()
    {            
        if (Button1.enabled == true)
        {
            readyToRun.enabled = true;
        }            
    }
}

1 个答案:

答案 0 :(得分:0)

尝试Gameobject.activeInHierarchy

http://docs.unity3d.com/ScriptReference/GameObject-activeInHierarchy.html

 GameObject.activeSelf;         //Returns if the object is active or not
 GameObject.activeInHierarchy;  //Return if the object is active in the scene

您应该使用setActive(true / false)

在场景中将gameobjects设置为活动/非活动状态
if(Button1.activeInHierarchy==true)
{
readyToRun.setActive(true);
}