【问题标题】:Unhide a Game Object when triggered an another game object触发另一个游戏对象时取消隐藏游戏对象
【发布时间】:2018-12-05 05:48:38
【问题描述】:

所以我有 2 个游戏对象。第一个游戏对象是 setActive(false);第二个游戏对象是我触发的那个,第一个游戏对象必须 setActive(true);但我似乎做不到.. 我只是 Unity 的初学者

#pragma strict
function Start () 
{
    GameObject.Find("jumpImage").SetActive(false);
}

function OnTriggerEnter(col:Collider)
{   
    if(col.tag=="Player")
    {
        GameObject.Find("jumpImage").SetActive(true);
    }       
}

【问题讨论】:

    标签: javascript unity3d


    【解决方案1】:

    GameObject.Find 仅查找您可以在 GameObject.Find 的文档中看到的“活动”游戏对象。

    话虽如此,如果您在 Start 和 OnTriggerEnter 函数之间引用相同的 GameObject,则最好在第一次找到它之后存储一个引用。

    #pragma strict
    
    var jumpImageGO : GameObject;
    
    function Start () 
    {
        jumpImageGO = GameObject.Find("jumpImage");
        if (jumpImageGO != null)
            jumpImageGO.SetActive(false);
    }
    
    function OnTriggerEnter(col:Collider)
    {
        if(col.tag=="Player")
        {
            jumpImageGO.SetActive(true);
        }       
    }
    

    【讨论】:

    • 先生。当我想将其设置为活动时,我可以添加延迟吗??
    • 当然,只需使用Coroutine 并设置延迟或使用WaitForSeconds
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-04
    • 2015-04-18
    相关资源
    最近更新 更多