Question by
reput33 · Sep 12, 2020 at 01:22 PM ·
2d2d gamecollision2d2d-gameplaykeypress
How can i do an action after i detect a collision2D && and a key/mouse button being pressed?
I want to do a mining action (2D) which happens only if you touch the rock (the collision) and a key being pressed but i cant do it so i am asking you all to help me.
Comment
Answer by mbro514 · Sep 12, 2020 at 06:36 PM
void Update()
{
if (Input.GetButtonDown("Dig"))
{
bool canMine = Physics2D.Raycast(transform.position, Vector2.right * direction, 0.5f, LayerMask.NameToLayer("Minable");
if (canMine)
{
Mine();
}
}
}
Something along those lines should be what you're looking for.