UNITY TUTORIAL | SCRIPTING | Time.deltaTime

 

1
“PlayerControl” Script from Space Shooter 2D
  • when trying to move Player,  add Time.deltaTime to make the movement soft
  • it makes action in Update(), independent from frame and dependent on time
1-1
Moving Player Smoothly

 

2
“PlayerControl” Script from Space Shooter 2D
  • let’s try to remove Time.deltaTime

 

2-1
Moving Player drastically

 

 

ezgif.com-video-to-gif (1)
Time.deltaTime

UNITY | PROJECT | 2D PlatFormer | 4. Score System

2
“PlayerScore” Script
  • create timeLeft & playerScore
  • in Update() method,
    • make timeLeft pass by using Time.deltaTime
    • create an if statement
      • when the time reaches approximately 0, load the scene again
  • in Awake() method,
    • temporarily, set the time into 5
3
“Player” Inspector

 

3-1
Time is passing

 

4
Creating “EndLevel”
  • create EndLevel from empty gameObject
    • add Box Collider
      • check is Trigger to make it as Trigger Collider
    • add RigidBody2D
      • set Body Type as Static
        • to make the gameObject immovable
        • the least resource-intensive body type
        • only collides with Dynamic RigidBody2D
        • Having two Static RigidBody2Ds colldie is not supproted
5
“PlayerScore” Score
  • create a Function, CountScore(),
    • update playerScore by calculating with timeLeft
    • create OnTriggerEnter2D()
      • put CountScore() in to make it activated when collisions happen

 

5-1
End Level
6
Creating UI

 

7
“PlayerScore” script
  • create GameObject variables for UIs
  • in Update() method,
    • use text property in UIs by using GetComponent()

 

7-1
UI Working

UNITY | PROJECT | SPACE SHOOTER 2D | 2. Player Input Movement

SPACE SHOOTER 2D

2. Player Input Movement

2
Player Control Script
  • Creating & Adding “PlayerControl” script

3
Player Control Script | Update() | Input.GetAxisRaw()
  • setting “speed” variable as public to see in the inspector
  • In “Update()”
    • set horizontal & vertical input by using Input.GetAxisRaw()
      • with Input.GetAxisRaw(), the values will be -1, 0 or 1
    • with the two inputs, make “direction”
      • by adding “.normalize”, make a unit vector
    • add a customized fuction “Move()” to move “Player”
      • we need this fuction in “Update()” because “Player”‘s position must be changed and detected every frame

 

4
Player Control script | Move() | Vector2 | Camera.main.ViewportToWorldPoint()

 

5
Player Control script | Move() | transform.position | Mathf.Clamp()
  • get the Player’s current position with “transform.position”
    • transform.position of the gameObject this script is attached to
  • calculate the new position in “currentPosition” variable
    • with “speed” variable, we can change the speed of “Player”
      • “direction” is the normalized vector2
      • “Time.deltaTime” is very important with this, we smooth the movement
2. Player Input Movement
without “Time.deltaTime”, the value(“direction”) is almost (0, 0), (1, 0)……

 

6
Setting Player’s Speed | Public Variable

 

1
Player Input Movement
2
Player Input Movement | without Time.deltatime
  • without “Time.deltaTime”, “Player” moves too dynamically

 

UNITY TUTORIAL | PROJECT | Roll a Ball | 5. Creating Collectable Objects

Roll a Ball

Creating Collectable Objects

2
Cube Object
3
deselection in the inspector
4
changing transform of Collectable
5
Attaching Script to
6
Public Variable | Transform.Rotate()
ezgif.com-video-to-gif
Rotating Cube
5. Creating Collectable Objects
Adding time.deltaTime | Frame Independent
ezgif.com-video-to-gif-2
Smooth Rotation with time.deltaTime
8
Trying to make Prefabs
9
Making Prefabs
10
Local View
11
Global View
ezgif.com-video-to-gif
Moving GameObject in Global View
12
Putting Prefabs | Values of Prefabs
13
Changing​ Values in Prefab Origin
14
Change applied to every Prefab
ezgif.com-video-to-gif-2
PickUps
5. Creating Collectable Objects
Creating Material​ to Change Color of Prefab
5-creating-collectable-objects-2.png
Apply the Material to an instantiated prefab
5. Creating Collectable Objects 3
Applying change to every prefab
ezgif.com-video-to-gif
Changing​ Color of

WEEK3 |UNITY 2D | Selection, Timer Part.1

Boolean Expression

  • Data Type – “bool”
  • evaluates “True” or “False
  • helps us with Selection Control Structure
    • lets us make decisions about which code to execute
      • Example 1) Movement Direction based on user input
      • Example 2) Whether or not an enemy drops loot
      • Example 3) Whether or not a player has leveled up
      • Example 4)
  • Logical Operators
    • And : “&&
    • Or : “| |”
    • Not : “!”
  • Relational Operators
    • ==
    • !=
    • <
    • <=
    • >
    • >=
6
Jumper.cs
7
Timer Logic