UNITY | PROJECT | SPACE SHOOTER 2D | 6. Explosion​ Animation

2
Explosion Sprite | Sprite Editor

 

4
Explosion Sprite | Sprite Editor | Slice

 

5
Explosion Sprite | Inspector
  • For the Sprite of Explosion in the Inspector
    • Set the Sprite Mode into “Multiple”
    • Set the Filter Mode into “Point(no filter)”
    • Set the Max Sie into “1024”
6
Creating Animation from Sprite

 

7
“ExplosionAnimationContoller”
8
“Explosion” GameObject

 

9.1
Deselect “Loop Time”

 

9.2
“Explosion” Animation
  • “Explosion” Animation is appearing continuously

 

 

9.3
“Explosion” Animation

 

  • “Explosion” Animation works well except that the last frame of the animation lasts in the scene

 

10
Creating & Adding “Destroyer” Script

 

11
“Destroyer” Script
12
“Animation” Tap
13
Adding an Animation Event to “Explosion” Animation

 

14.1
Adding an Animation Event to “Explosion” Animation
14.2
“Explosion” Animation
15
Creating “Explosion” Prefab

UNITY | PROJECT | SPACE SHOOTER 2D | 5. Enemy Bullet & Enemy Shooting

2
Adding “EnemyBullet” Sprite to the scene to configure
3
Creating & Adding “EnemyBullet” Script
4
“EnemyBullet” Script
  • Create Variables for “speed”, “direction”, “flag”
  • Create a Function to set the Bullet’s Direction, “SetTheDirection(Vector2 direction)”
    • Be careful not to be confused with the names of variable “direction”
      • to differentiate them, put “this.” in front of “direction”(not the argument)
    • normalize the vector to get purely a direction (to make the computing correct and simple)
    • set the flag(the boolean variable) as “True” to activate the codes in “Update()” method
  • In “Update()” method
    • the codes will be activated when the flag is set to “True”
    • the position of the bullet is updated every frame by calculating “transform.position” with “direction(Vector2, the result from “SetDirection()”)’
    • if a bullet goes out of the screen, Destroy it
  • In “Awake()”
    • every code in “Awake()” is activated before the game starts
    • before the game starts, set “speed” and “ready” with default values

 

5
Creating “EnemyBullet” Prefab

 

6
Add “Enemy” Prefab temporally to configure

 

7
Adding “EnemyGun” to “Enemy” by creating Empty GameObject | Adding “EnemyGun” Script

 

11
“EnemyGun” Script
  • Add a public GameObject variable to use EnemyBullet prefab as a component
  • Create a Function to fire bullets from Enemy, “FireEnemyBullet()”
    • get a reference of “Player” by using “GameObject.Find()”
    • the way of detecting a GameObject, “if(gameObject != null)”
    • if “Player” is detected, a bullet is instantiated and its initial position is set
    • how to calculate an aiming direction: Vector – Vector
    • to use “SetDirection()” method of “EnemyBullet” Class, use “GetComponent()” towards “bullet”
  • In “Start()” method
    • make “FireEnemyBullet()” activated after 1 second, by using “Invoke()”

 

12
Don’t forget to add the reference in the Inspector

 

13
Applying Changes to Prefab
  • To apply changes on the prefab, Don’t forget to push “Apply” button in the Inspector

 

14
Enemies Spawning, Moving, and Shooting

UNITY | PROJECT | SPACE SHOOTER 2D | 3. Player Bullet and Player Shooting

SPACE SHOOTER 2D

3. Player Bullet and Player Shooting

3
Bullet Sprites
  • Importing “Bullets” sprite

 

5
Sprite Editor | Slice

 

  • 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

 

4

  • Having 2 bullet sprites

 

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

 

7
Adding prefab in the scene
  • Add “Player Bullet” sprite in the scene to configure like adding a script

 

8
Adding a script to Bullet GameObject
  • Adding “PlayerBullet” script to “PlayerBullet” GameObject

 

9
“PlayerBullet” Script
  • 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()”

 

10
Setting the speed in the inspector | Public Variable
ezgif.com-video-to-gif
Shoot a bullet

 

11
Making a Prefab
  • Make the Bullet Prefab by dragging the bullet we configured in the Hierarchy window
    • this is the Bullet we will continuously instantiate

 

12
Empty GameObject

 

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

 

15
Child Object
  • Make “BulletPosition” as a ChildObject of “Player”
    • “BulletPosition” belongs to “Player”

 

16
“Player Control
  • Set Public Variables to use those components in the script

 

17
Public Variable | Reference

 

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

 

ezgif.com-video-to-gif-2
Player Shooting | Destroying Bullets

 

UNITY TUTORIAL | PROJECT | SPACE SHOOTER |11. Game Controller

UNITY TUTORIAL | PROJECT | SPACE SHOOTER |11. Game Controller

2
adding “Game Controller”

 

3
adding “GameController” Script

 

6
Instantiating “Asteroid” as “hazard” | deciding the location and rotation of instantiation

 

7
using a temporary prefab to get Transform values

 

8
putting the values in a public variable as a medium

 

9
instantiating GameObject in random locations by using Random.Range()

 

11
Quaternion.identity, no rotating

 

ezgif.com-video-to-gif
Instantiating “hazard” 1
ezgif.com-video-to-gif-2
Instantiating “hazard” 2

UNITY TUTORIAL | PROJECT | SPACE SHOOTER |6. Creating Shots

UNITY TUTORIAL | PROJECT | SPACE SHOOTER |6. Creating Shots

2
creating Empty GameObject & Quad for Shot
3
Texture for Laser
4
creating Empty Material to create Material for shot
5
creating Material
6
adding Material to “Mesh Renderer”
7
Mesh Renderer | Material | Shader
8
changing Shader for Laser | Particle – Additive
9
deleting collider for VFX
10
adding RigidBody & Capsule Collider to Shot | Trigger Collider
11
Creating Prefab
12
“Mover” Script for shot | RigidBody.Velocity | Start()
13
deleting instance of shot
ezgif.com-video-to-gif
creating instances of laser