How Could I Shoot In My Top Down 2D Game

In My Game I Want To Make It So When I Press the up arrow i shoot up and if i press the right arrow it shoots right etc but i cant find anything or figure it out so plz help…

Hi Yoğurt,

First of all, you’ll need to work on shooting mechanics. And then you’ll need to be able to get key events. It seems like you lack the basics of Unity programming.

So, here’s a really nice tutorial: Unity for 2D: New Workflows in Unity 4.3 - Unity Learn

This tutorial includes shooting mechanics and key event handling. It will also give you a very nice basics on 2D mechanics in Unity.


You need to change your shooting point rotation according to your input so here’s a basic code, since you have the grasp on Unity basics:

 void Update() {
        if (Input.GetKey("up"))
            transform.rotation  = Quaternion.LookRotation(Vector2.forward, Vector2.up);
        
        if (Input.GetKey("down"))
            transform.rotation  = Quaternion.LookRotation(Vector2.forward, Vector2.down);

        if (Input.GetKey("left"))
            transform.rotation  = Quaternion.LookRotation(Vector2.forward, Vector2.left);

        if (Input.GetKey("right"))
            transform.rotation  = Quaternion.LookRotation(Vector2.forward, Vector2.right);
    }

thanks but i know the basics such as instantiate and keycodes and even transform.translate im just needing to know how i could shoot ps my game is top down so i should be able to shoot in all directions