WEEK3 |UNITY 2D | if and switch statement

ec8aa4ed81aceba6b0ec83b7-2018-05-16-ec98a4ed9b84-4-56-46.png
if statement
스크린샷 2018-05-16 오후 4.56.51
switch statement

switch (variable)

{

case (value of the variable) :

—body—

break;

.

.

default : (=> else)

—body—

break;

}

스크린샷 2018-05-16 오후 4.57.04스크린샷 2018-05-16 오후 4.57.13스크린샷 2018-05-16 오후 4.57.31스크린샷 2018-05-16 오후 4.57.38스크린샷 2018-05-16 오후 4.57.44

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

WEEK3 |Unity 2D Physics | Prefabs, Collider

Prefab

  • a prefabricated gameObject
  • a gameObject we have configured the way we want, then saved as a prefab
  • easily adding instances of the prefab to a scene in the editor
  • easily adding instances of the prefab to a scene from a script(spawning)
5
Prefabs | Sprite
6
Prefabs | Sprite change

 

9
Component added to Prefab

 

7
Component applied to GameObject from Prefab
83.png
Component applied to GameObject from Prefab
10
RigidBody2D | GetComponent() | Rigid
11
Script attached to a GameObject
12
Script working in a GameObject
13
Inspector | Prefab Apply
14
Prefab change Applied

 

Collision Detection

  • Detecting collisions between gameObject
  • if both game objects have 2D collider, the Physics 2D engine automatically does collision detection
15
Edge Collider
16
Box Collider
17.png
Physics Material
18
Physics applied to Collider

Collision Resolution

  • Doing something based on the fact that a collision has been detected
  • 2D Physics materials for the game object colliders determine how the Physics 2D engine resolves the collision(Friction/Bounciness)
  • Additional collision resolution by ourselves is possible
19
OnCollisonEnter2D
20
OnCollisionEnter2D

 

WEEK3 |Unity 2D Physics | Moving GameObject

2
GameObject | Unity Component | RigidBody2D
5
Physics 2D | Gravity
6
Project Settings | Physics 2D
8
Physics2D
10
Physics2D Setting | Gravity
9
RigdBody2D | GetComponent | RigidBody2D.AddForce

GetComponent

  • we can get other components that are attached to the same Game Object this script is attached to by calling “GetComponent” and we put that component into a variable

RigidBody2D.AddForce

  • public void AddForce(Vector2 force, ForceMode2D mode = ForceMode2D.Force);
  • ForceMode2D
    • ForceMode2D.Force – Add a force to the Rigidbody2D, using its mass.
    • ForceMode2D.Impulse – Add an instant force impulse to the rigidbody2D, using its mass.
11
Script Attached
12
GameObject Moving