Question by
KonradoZombie · Dec 07, 2020 at 08:30 PM ·
scripting problem
Trobule with Item pickup.
Ok, so I'm struggling with something simple. I'm trying to make the Player "Pick up" an "Item". First an image appears to hint the "Player" and then when Space is pressed I want to disappear the Item (destroy it). But the second "if" statment doesn't work inside the first one. Can anyone help me? :(
Here's my code:
void OnTriggerEnter(Collider col) { if (col.gameObject.CompareTag("Item")) { QuestionMark.SetActive(true);
itemTriggered = true;
}
if (itemTriggered && Input.GetKeyDown(KeyCode.Space))
{
print("space key was pressed");
QuestionMark.SetActive(false);
itemTriggered = false;
Destroy(col.gameObject);
}
}
void OnTriggerExit(Collider col)
{
if (col.gameObject.CompareTag("Item"))
{
QuestionMark.SetActive(false);
itemTriggered = false;
}
}
Comment
Your answer