위의 게임은 외계인 적들의 추적을 피하여 적들을 없애거나 피하여 생존하는 게임입니다.
- 일정한 시간마다 ALIEN(적 외계인)이 생성됩니다. 생성될 때마다 외계인을 피하거나 외계인을 없애서 점수를 획득하는 방식으로 스테이지에서 생존합니다.
- HP가 0이 되었을 때 게임이 종료되며, 그때 마지막으로 기록된 스테이지와 점수가 기록으로 남습니다.
- 이 게임의 성공과 실패가 적용되는 플레이어블 캐릭터입니다.
- 전, 후, 좌, 우로 움직일 수 있습니다.
- ALIEN과 충돌하면 HP가 0이 되며 게임이 종료됩니다.
- 바닥 LIGHT와 접근하여 빨간색에서 초록색으로 만들 수 있습니다.
- 플레이어를 공격하는 적입니다.
- 플레이어를 탐지하는 로직으로 플레이어를 추적합니다.
- 플레이어에게 충돌하면 플레이어의 HP가 0이 되며, 바닥 LIGHT의 초록색에 닿으면 소멸 판정됩니다.
- 스테이지 바닥에 위치합니다.
- 플레이어가 더 오래 생존하게 하는 게임 장치입니다.
- 플레이어는 캐릭터 컴포넌트를 사용하여 이동합니다.
InputMagnitude()함수로 캐릭터 방향을 입력받으며, 입력된 이동 방향으로 이동됩니다.
void InputMagnitude()
{
//Calculate Input Vectors
InputX = Input.GetAxis("Horizontal");
InputZ = Input.GetAxis("Vertical");
//Calculate the Input Magnitude
Speed = new Vector3(InputX, InputZ).sqrMagnitude;
//Physically move player
if (Speed > allowPlayerRotation)
{
playerAnimator.SetBool("isRunning", true);
playerAnimator.SetBool("isIDLE", false);
PlayerMoveAndRotation();
}
else if (Speed < allowPlayerRotation)
{
playerAnimator.SetBool("isRunning", false);
playerAnimator.SetBool("isIDLE", true);
}
}-PlayerMoveAndRotation() 함수를 사용하여 캐릭터의 방향 회전을 구현합니다.
void PlayerMoveAndRotation()
{
InputX = Input.GetAxis("Horizontal");
InputZ = Input.GetAxis("Vertical");
var camera = Camera.main;
var forward = cam.transform.forward;
var right = cam.transform.right;
forward.y = 0f;
right.y = 0f;
forward.Normalize();
right.Normalize();
desiredMoveDirection = forward * InputZ + right * InputX;
if (!blockRotationPlayer)
{
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(desiredMoveDirection), desiredRotationSpeed);
controller.Move(desiredMoveDirection * Time.deltaTime * Velocity);
}
}####적의 플레이어 탐지 및 이동 #####ALIEN은 플레이어가 탐지되지 않았을 때 AddForce를 통해 이동하며, Raycast를 통해 플레이어를 탐지한 후 추적합니다.
if (monsterSpawner.isMonsterMove)
{
if (Physics.Raycast(transform.position, transform.forward, out hit, maxDistance))
{
transform.position = Vector3.MoveTowards(transform.position, playerVector, Time.deltaTime * monster_speed);
}
else
{
await EnemyMoveSequence().SuppressCancellationThrow();
}
}####Collider의 isTrigger를 이용하여 플레이어가 바닥 빛이 적색일 때는 초록색으로 만들고, 초록색일 때 ALIEN이 지나가면 ALIEN이 소멸된 후 다시 빨간색으로 바뀌도록 구현합니다.
private void OnTriggerEnter(Collider other)
{
if (!spawner.isLightReset)
{
if (other.gameObject.tag == "Player")
{
this.transform.GetChild(0).GetComponent<Light>().DOColor(Color.green, 0.1f);
}
if (other.gameObject.tag == "EnemyAlien")
{
if (this.transform.GetChild(0).GetComponent<Light>().color == Color.green)
{
Destroy(other.gameObject, 0.5f);
this.transform.GetChild(0).GetComponent<Light>().DOColor(Color.red, 0.1f);
spawnSO.recentPoint += 10;
}
}
}
}