Problem with bullets in 2D game Unity C#

Hi,

I’m programming a 2D Game in Unity with C#

I created 4 game objects for bullets going in 4 directions: (bullet, left bullet, top bullet, bottom bullet)

They all fly in the correct direction now. I did that in the Unity Inspector. Currently, the bullets fly away after pressing ‘play’ in Unity, in all 4 directions.
But I want them to fly away after pressing spacebar on the correct direction. So if the player is walking right to shoot to the right, if he’s walking to the left, shoot to the left etc.

All 4 bullet objects have a circle collider 2D and a Rigidbody 2D and are linked to the bullet.script.

And the main character has a script called player_script.
Please find both scripts attached
Any help would be greatly appreciated !
Thanks in advance


Privacy & Terms