Search code examples
unity-game-engineunityscript

Unity 2D: How would I go about making a block that shoots when the player touches it?


I am making a 2D platformer in Unity and I want to make a block that works very similarly to the shooting blocks from Kid Chameleon. When they are touched by the player, they shoot from what every direction the mark is on and the bullet can hurt the player and enemies, destroy crates and activate other shooting blocks. Can some one tell me how I can achieve this because I have no idea where to start?


Solution

  • For start you can use OnMouseDown() event for detecting a click(or touch) on an object and then you can Instantiate a bullet object from block and give it's rigidbody a velocity to move towards that. and you can use OnCollisionEnter2D(Collision2D c) event for every Gameobject that you want to detect collision and do your job.