UNITY | Project | RPG Tutorial |22. Main Menu

2
New Scene | Plane
3
Creating Texture
4
Creating Plane | Adding Texture
  • create 2 planes as the background of Main Menu
  • make them stand towards Main Camera
5
Adding Logo to Plane | Shader
6
Texture Created Automatically
  • add logo image
  • after adding an image to Shader, the material is created automatically
7
Child Object
8
Rotating BackGround
  • rotate the background a little for the scene not to be seen though the logo
9
Lighting | Sky Box
10
Adding UI Text
11
Effects – Particle system
12
Adding Particle System
13
Creating UI Buttons
14
Creating Side Bar with UI Button
15
Side Bar
16
Creating UI Button
17
Creating Animation for Sliding Bar
18
Adding Animation
19
Animaiton | Wrap Mode
  • create a UI Button covering all the screen, but invisible
    • for “click anywhere to start”
20
“MenuControl” Script
  • create variables
    • for the empty gameObject, “menuSlider”
  • create a function, SlideMenu(),
    • when the function is activated, play the menu sliding animation

 

21
Adding Script
22
UI Button | On Click() | Adding Function
23
“MenuControl” Script
  • add variables,
    • for UIs to disappear after Side Menu appear
AC_28
Main Menu Working

UNITY | Project | RPG Tutorial | 19. NavMesh & Boss AI

2
“NPC001” Script
  • when Player finishes the first Quest, change the saying of NPC by changing QuestNumber in QuestManager
3
Adding Trigger for Gate
  • Adding Cube for Trigger for opening Gate
4
“Quest002Start”
  • creating variables
    • for distance between Player and NPC
    • UI – Buttons
  • in Update() method,
    • getting the distance by using PlayerCasting
  • in OnMouseOver() method,
    • if Player is close enough to NPC
      • prevent Player from attacking
      • set the UI Text with messeges for Gate
      • if Action Button pressed
        • allow Player to attack
        • allow Player to use
        • turn off UI Text
ezgif.com-optimize.gif
NPC saying Different
5
Adding Cube as Walkable Ground
  • add Cube as a boundary for the boss to walk
6
Windows – AI – Navigation
7
Navigation | Walkable
8
Naviagtion | Bake
9
Turning off Mesh Renderer
10
NavMesh Agent
11
“SpiderBossAI”
  • create variables
    • where spider boss goes
    • NavMeshAgent
  • in Start() method,
    • make the NavMeshAgent variable NavMeshAgent
  • in Update() method,
    • through the NavMeshAgent variable, set where the boss to go
12
Adding Script
13
Animation
14
Animation | WrapMode
15
Creating Barriers
16
Barriers | Navigation | Non Walakble
17
Barriers | Bake | Bake
  • to prevent the boss from walking through the barriers, bake the barriers Non Walkable
18
SpiderBoss | NavMesh Agent | Radious like Collider
18-1
SpiderBoss Moving
19
Adding Cube as Trigger
  • put Spider Boss in a Cube Object named SpiderBossTrigger as child object
18-2
SpiderBoss Following Player
20
Adding Attack Animation
21
“SpiderBossAttack” Script
  • create variables
    • spider boss itself
    • as flag for attacking
  • in Update() method,
    • if attackTrigger is 0
      • make the boss walk with the animation
    • if attackTrigger is 0
      • if dealDamage  is 0
        • get the boss attack by player the animation
        • get the coroutine TakingDamage started
  • create IEnumerator TakingDamage()
    • set dealDamage into 2
    • wait for 1.1 sec
    • if spider’s status is not dead
      • get rid of one heart of Player
    • wait for 0.5 sec
    • set dealDamage into 0
  • in OnTriggerEnter() method,
    • when the boss touches Player, set attackTrigger into 1
  • in OnTriggerExit() method,
    • when Player gets out of the boss, set attackTrigger into 0
22
Adding Script
  • Adding Script
  • put SpiderBoss in the script
22-1
Spider Boss Following & Attacking Player

UNITY TUTORIAL | SCRIPTING | GetComponent()

Unity Tutorial | Scripting |Getcomponent()

 

Script itself is a custom game component

also, in a script, we can modify other components such as “RigidBody”, “Collider”, or even another “Script”

to modify components in a script we need variables as a bowl for the component and we need to put the component in the variable by using “GetComponent()”

 

2
“PlayerControl” Script | Creating a Varaible
  • Create a variable “GameManager” as a bowl to bring and use “Gamemanger” script or class in this script
3
“GameManager” Script | Custom Function
  • there is a custom function, “SetGameManagerState()” in “GameManager” script or calss
4
“PlayerControl” Script | GetComponent()
  • put the class in the variable by using “GetComponent()”
  • after that, we can use the functionality of “GameManager” class in this script

 

5
“Player” GameObject | Inspector | Audio Source
  • in “Player” GameObject,
    • “PlayerControl” scrip & “Audio Source” are attached
    • we want to use  “Audio Source” in “PlayerControl” Script
6
“PlayerControl” Script | GetComponent()
  • In “PlayerControl” Script,
    • create a variable as a bowl for “Audiosource”
    • put the class by using “GetComponent()”
    • use “AudioSource”

UNITY | PROJECT | 2D PlatFormer | 1. Project Set Up

2
Importing Sprites

 

3
Cutting Sprites

 

4
Creating “Ground”
  • Add “Box Collider” to “Ground”

 

5
Adding “Player”
  • Add “Box Collider” to “Player”
  • Add “RigidBody2D” to “Player”
7.1
Adding “PlayerControl” Script
7.2
Physics Working

 

8
“PlayerControl” Script
  • Claim variable for Player movement
    • playerSpeed
    • facingRight as flag
    • playerJumpPower
    • movementX
  • in “Update()” method
    • get input to move horizontally by using “Input.GetAxis()”
    • get “RigidBody2D” component by using “GetComponent()”
      • call “velocity” propery to move “Player” with continuous input
    • create “if Statement” for Player’s movment
      • when pressing left and facing right
        • activate “FlipPlayer()” method
      • when pressing right and facing left
        • activate “FlipPlayer()” method
    • Create a Function, “FlipPlayer()”,
      • set the flag, “facingRight” to opposite
      • get the “localScale” property
        • multiply -1 to reverse the direction
      • Don’t forget to update “localScale”
10.2
Player Moving
9
“PlayerControl” Script
  • Create a function, “Jump()’,
    • use “AddForce()” to give force upwards to “Player”
  • in “PlayerMove()” method,
    • when “Jump” button is pressed, activate “Jump()” method

 

10.1
Input Manager

 

10.3
Player Jumping too high

 

11.1
RigidBody2D | Linear Drag | Gravity Scale
  • Set “Linear Drag” 0 to 1 to prevent “Player” from jumping too much
  • Set “Gravity Scale” 0 to 10 to prevent “Player” from jumping too much

 

11.2
Player Jumping
  • Player jumps normally but still it can jump multiple times in the air

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