- Home /
 
Destroying object when player walks over it
My Game is a 2D game and i have a pistol sprite in my level and the animation for my player holding it is set up in the animation but how would i say in my script that i want the animation to play and the object to destroy when the player walks over it? void OnColliderEnter(Collider2D Pistol) { Destroy(Pistol.gameObject);
     anim.SetTrigger ("isIdlePistol");
     Debug.Log ("Picking up pistol");
 }
 
               this is the script i used but doesn't work :/.
Answer by bartbussel · Dec 08, 2017 at 03:25 PM
Try using
OnCollisionEnter2D
instaid of
OnColliderEnter.
 private void OnCollisionEnter2D(Collision2D collision)
     {
         Destroy(collision.gameObject);
         anim.SetTrigger("isidlepistol");
 
     }
 
              ok this still does nothing
private void OnCollisionEnter2D(Collision2D Pistol) { Destroy(Pistol.gameObject); anim.SetTrigger("isidlepistol");
 }
                 Your answer
 
             Follow this Question
Related Questions
Trigger Animation doesn't work, please help me. 1 Answer
Destroy the gameObject after seconds when not hit. 0 Answers
Something wrong with destroying script 0 Answers
How to check if sprites are overlapping and by how much? 0 Answers
How to create a collider-trigger that will start an animation when you press E 0 Answers