728x90
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;
}
void OnDestroy()
{
Guard.OnGuardSpottedPlayer -= Disable;
}
}
|
Player 스크립트에 위의 코드를 추가해준다. OnTriggerEnter 함수를 통해서 만약 플레이어가 종류 지점에 들어가게 된다면 Disable 함수를 실행시켜 Player를 움직이지 못하게 해주고 OnReachEndOfLevel을 실행시켜준다.
만약 Guard가 게임 도중에 플레이어를 검거하여 OnGuardSpottedPlayer가 실행되면 플레이어를 움직이지 못하게 하기 위하여 Start 함수에서 OnGuardSpottedPlayer에 Disable를 추가해준다.
게임이 재시작되고 OnGuardSpottedPlayer가 실행되게 될 때 Disable이 2번 실행되지 않도록 OnDestroy 함수에 OnGuardSpottedPlayer에서 Disable을 빼준다.
728x90
'Project > 도둑과 경호원' 카테고리의 다른 글
[도둑과 경호원] Unity: Sysyem.Action을 이용한 이벤트 (0) | 2020.05.06 |
---|---|
[도둑과 경호원] Unity: Guard 플레이어 검거하기 (0) | 2020.05.05 |
[도둑과 경호원] Unity: Player 회전과 이동 (0) | 2020.05.04 |
[도둑과 경호원] Unity: Guard 기즈모 (0) | 2020.05.03 |
[도둑과 경호원] Unity: Guard 회전하기 (0) | 2020.05.02 |