본문 바로가기

728x90

Project/도둑과 경호원

(8)
[도둑과 경호원] Unity: event 적용시키기 System.Action으로 만들었던 이벤트 UI를 Player와 Guard 스크립트에 적용시켜보겠다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 public class Player : MonoBehaviour { void Start() { Guard.OnGuardSpottedPlayer += Disable; } void OnTriggerEnter(Collider other) { if(other.tag == "Finish") { Disable(); if(OnReachEndOfLevel != null) { OnReachEndOfLevel(); } } } void Disable() { disabled = true..
[도둑과 경호원] Unity: Sysyem.Action을 이용한 이벤트 System.Acition(delegate)을 이용하여 이벤트를 발생시키는 방법에 대해서 알아볼 것이다. 이 방법은 이번에 공부하면서 알게 된 방법이다. 이 방법의 좋은 점은 단지 System.Action에 저장되어있는 함수를 실행하는 것을 목적으로 하기 때문에 Guard나 Player 스크립트가 사라져도 오류를 반환하지 않는다는 점이다. 1 2 3 4 5 6 7 8 9 public class Guard : MonoBehaviour { public static event System.Action OnGuardSpottedPlayer; } public class Player : MonoBehaviour { public static event System.Action OnReachEndOfLevel; } 먼..
[도둑과 경호원] Unity: Guard 플레이어 검거하기 Guard에게 플레이어가 일정 범위 안에 들어갔을 때 플레이어를 검거할 수 있는 로직을 구현해보겠습니다. 1 2 3 4 5 6 7 8 9 10 public Light spotLight; public float viewDistance = 5; public LayerMask viewMask; public float timeToSpotPlayer = 0.5f; float playerVisibleTimer; float viewAngle; Transform player; Color originalSpotlightColor; spotLight - Guard가 가지고 있는 spotLight를 저장할 변수이다. viewDistance - Guard가 플레이어를 검거할 수 있는 직선거리이다. viewMask - Laye..
[도둑과 경호원] Unity: Player 회전과 이동 이번에는 Player가 움직이는 키에 맞게 회전하여 움직이는 방법에 대해 알아보겠다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour { public float moveSpeed = 7; public float smoothMoveTime = 0.1f; public float turnSpeed = 8; float angle; float smoothInputMagnitude; float smoothMoveVelocity; bool disabled; Vector3 velocity; Ri..
[도둑과 경호원] Unity: Guard 기즈모 OnDrawGizmos는 개발자가 진행 상황들을 편하게 보기 위해서 Game뷰에 기즈모들이 보이게 해주는 것이다. 이 함수를 사용하여 개발자는 게임뷰를 보면서도 씬뷰를 보는 것과 같이 볼 수 있고 오류는 없는지 보다 정확한 판단을 하게 해줄 수도 있다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 void OnDrawGizmos() { Vector3 startPosition = pathHolder.GetChild(0).position; Vector3 previousPosition = startPosition; foreach(Transform waypoint in pathHolder) { Gizmos.DrawSphere(waypoint.position, 0.3f); Gizmos.D..
[도둑과 경호원] Unity: Guard 회전하기 이번에는 Guard가 이동하는 방향에 맞게 회전하는 것을 구현하겠다. 1 2 3 4 5 6 7 using System.Collections; using System.Collections.Generic; using UnityEngine; public class Guard : MonoBehaviour { public float turnSpeed = 90; Guard 움직이기에서 turnSpeed를 추가로 선언해주면 된다. turnSpeed - Guard가 회전하는 속도에 대한 값을 저장하는 변수이다. 1 2 3 4 5 6 7 8 9 10 11 12 IEnumerator TurnToFace(Vector3 lookTarget) { Vector3 dirToLookTarget = (lookTarget - trans..
[도둑과 경호원] Unity: Guard 움직이기 가장 먼저 Guard 스크립트에 대해서 설명하겠다. 1 2 3 4 5 6 7 8 9 10 using System.Collections; using System.Collections.Generic; using UnityEngine; public class Guard : MonoBehaviour { public float speed = 5f; public float waitTime = 0.3f; public Transform pathHolder; Guard를 움직이기 위해 필요한 변수들이다. speed - 움직이는 속도 값을 가지고 있는 변수이다. waitTime - 다음 지점으로 가기 전에 잠깐 기다리는 시간을 가지고 있는 변수이다. pathHolder - Guard가 움직이는 지점에 대한 정보를 가지고 ..
[도둑과 경호원] Unity: 게임 기획 스크립트 Player - 플레이어 움직임과 게임 종료를 다룬다. Guard - 경호원의 움직임과 플레이어 발견을 다룬다. GameUI - 게임 승리와 종류 UI에 대해 다룬다. FollowCamera - mainCamera가 플레이어를 추척하는 것에 대해 다룬다. 게임 오브젝트 플레이어 수평축 입력키와 수직축 입력키로 이동을 할 수 있다. 경호원 손전등을 가지게 된다. 정해진 길에 따라서 이동한다. 일정 시간 이상 플레이어를 보게 되면 게임을 종료시킨다. 종료 지점 플레이어가 종료 지점에 들어오게 되면 게임을 승리하게 된다. 미니맵 위에서 바라본 게임 진행 상황을 볼 수 있는 화면이다. 게임 방법 플레이어는 경호원에게 들키지 않고 목표지점까지가는 것이 게임의 목표이다. 경호원은 정해진 길을 따라 순찰을 ..

728x90