[英]How Do I Destroy The Collided GameObject When The Pickup Button Is Pressed (X) In Unity
I need to make my GameObject (pickup) get destroyed when the player enters its trigger and presses x to pick it up.我需要让我的游戏对象(拾取)在玩家进入触发器并按下 x 拾取它时被销毁。
This is what I've got so far.这是我到目前为止所得到的。 this is on the pickup that needs to be destroyed:
这是在需要销毁的皮卡上:
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;
}
}
and this is on the Player That Is Colliding with the Pickup's Trigger:这是在与拾音器触发器碰撞的播放器上:
if (UIManager.AbleTopickUp)
{
if (Input.GetButtonDown("XButton"))
{
UIManager.XButtonPressed = true;
if (currentSlot == 1)
{
Slot1_W = 1;
}
if (currentSlot == 2)
{
Slot2_W = 1;
}
if (currentSlot == 3)
{
Slot3_W = 1;
}
}
}
Any help will be appreciated任何帮助将不胜感激
用OnTriggerEnter
替换OnTriggerStay
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.