Start 1: 2025/02/25 19:43 ~ 2025/02/25 20:58
→ B18 00:00 ~ B18 17:18
Start 2: 2025/02/25 21:25 ~ 2025/02/25 22:21
→ B18 17:19 ~ B18 37:07
Start 3: 2025/02/25 23:57 ~ 2025/02/26 00:08
→ B18 37:08 ~ B18 39:32
→ Complete
⇒ Enemy 생성 & Invoke 호출 & Animation 적용하기
Enemy
Rigidbody 2D
Active
Circle Collider 2D
Enemy.controller
Parameter: isWalking
(Boolean)
Enemy_Idle
↔ Enemy_Walk
State 간 Inspector 조정
Deactive
0
isWalking
조절EnemyMove.cs
using UnityEngine;
public class EnemyMove : MonoBehaviour
{
Rigidbody2D rigid;
void Awake()
{
// Rigidbody 2D
rigid = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
// Left Move
rigid.linearVelocity = new Vector2(-1, rigid.linearVelocity.y);
}
}
EnemyMove.cs
using UnityEngine;
public class EnemyMove : MonoBehaviour
{
Rigidbody2D rigid;
// Next Move
public int enemyNextMove;
void Awake()
{
// Rigidbody 2D
rigid = GetComponent<Rigidbody2D>();
EnemyThink();
}
void FixedUpdate()
{
// Random Move
rigid.linearVelocity = new Vector2(enemyNextMove, rigid.linearVelocity.y);
}
void EnemyThink()
{
// Random Moving Direction
enemyNextMove = Random.Range(-1, 2);
}
}
public int nextMove
: Enemy의 다음 움직임을 제어할 정수형 변수private void EnemyThink()
: nextMove 변수를 통해 행동지표를 바꿔줄 함수 생성
Random
: 난수를 생성하는 로직 관련 클래스
Random.Range(Min, Max)
: Min
~ Max - 1
사이 범위의 난수 생성 함수
nextMove
값 자체가 Enemy의 이동 방향을 대신할 수 있음
Value | Meaning |
---|---|
-1 |
Enemy moves to the left |
0 |
Enemy stops |
+1 |
Enemy moves to the right |