在Unity中按下(X)拾取按钮后如何销毁碰撞的游戏对象

时间:2019-12-16 20:25:30

标签: c# unity3d

我需要使我的GameObject(拾取)在玩家进入触发器并按x拾取时被破坏。

这是我到目前为止所掌握的。 这是需要销毁的皮卡:

<html>
    <body>
    <head>
    <title>
    View Books
    </title>
    </head>
    <body>
    <table border=2>
    <tr>
        <th>Book ID</th>
        <th>Title</th>
        <th>Author</th>
        <th>No. of copies  AVAILABLE</th>
        <th>Number of favourites</th>
    </tr>


    <tr>
        <td><%=b.bookID%></td>
        <td><%=b.bookTitle%></td>
        <td><%=b.bookAuthor%></td>
        <td><%=b.bookCopies%></td>
        <td><%=b.bookFavs%></td>    
    </tr>
    <%
        }
    %>
    </table>

    </body>
</html>

这是在与拾音器的触发器发生冲突的播放器上:

public void Update()
{
    if (UIManager.XButtonPressed == true)
    {
        UIManager.AbleTopickUp = false;
        UIManager.XButtonPressed = false;
        Destroy(this.gameObject);
        Debug.Log("Destroyed the pickup.");
    }
}


void OnTriggerEnter(Collider collision)
{
    if (collision.gameObject.name == "Player")
    {
        UIManager.AbleTopickUp = true;
    }
}

void OnTriggerExit(Collider collision)
{
    if (collision.gameObject.name == "Player")
    {
        UIManager.AbleTopickUp = true;
    }
}

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

OnTriggerEnter替换为OnTriggerStay