SPACE SHOOTER 2D
3. Player Bullet and Player Shooting

- Importing “Bullets” sprite

- by using “Sprite Editor”, slice “Bullets” sprites into 2 sprites
- when slicing, set the type into “Grid By Cell Size”
- when slicing, set the Pixel Size as 24×24

- Having 2 bullet sprites

- for the bullet sprite in the inspector
- deselect “Generate Physics Shape”
- Filter Mode into “Point(no filter)”
- Max Size into “1024”

- Add “Player Bullet” sprite in the scene to configure like adding a script

- Adding “PlayerBullet” script to “PlayerBullet” GameObject

- set the public variable “speed” for the speed of the bullet
- In “Update()” method
- get the bullet’s current position by using “transform.position”
- computing the bullet’s new position = the change of position when we shoot the bullet
- only need to change the “y” value
- to smooth the shooting, use “Time.deltaTime”
- Don’t forget to update the position into “transform.position”
- for the memory usage, destroy the bullets going outside the screen
- when setting the screen range, only consider “y” value or “height”
- “Camera.main.ViewPortToWorlPoint()”



- Make the Bullet Prefab by dragging the bullet we configured in the Hierarchy window
- this is the Bullet we will continuously instantiate



- Make 2 Empty GameObject to Create “BulletPosition”, where Bullets come out
- Set the position of “BulletPosition” on “Player” GameObject

- Make “BulletPosition” as a ChildObject of “Player”
- “BulletPosition” belongs to “Player”

- Set Public Variables to use those components in the script


- In “Update()” method
- Instantiate Bullet Prefab when “SpcaeBar” is pressed
- set the initial position of a bullet after instantiating













