강물 위치에 배치되있음.
Remover 스크립트가 할당되있고, 몬스터가 강물에 빠지면 해당 오브젝트를 제거하고 플레이어가 빠지면 특정 작업을 한후 재시작함.
// If the player hits the trigger...
if(col.gameObject.tag == "Player")
{
// .. stop the camera tracking the player
GameObject.FindGameObjectWithTag("MainCamera").GetComponent<CameraFollow>().enabled = false;
// .. stop the Health Bar following the player
if(GameObject.FindGameObjectWithTag("HealthBar").activeSelf)
{
GameObject.FindGameObjectWithTag("HealthBar").SetActive(false);
}
// ... instantiate the splash where the player falls in.
Instantiate(splash, col.transform.position, transform.rotation);
// ... destroy the player.
Destroy (col.gameObject);
// ... reload the level.
StartCoroutine("ReloadGame");
}
else
{
// ... instantiate the splash where the enemy falls in.
Instantiate(splash, col.transform.position, transform.rotation);
// Destroy the enemy.
}
메인카메라의 CameraFollow 스크립트 기능 끄기
HealthBar 활성화 상태이면 안보이게 하기 (activeSelf -> 오브젝트 활성화 여부 체크)
Splash 프리팹 생성 -> 강물 빠지는 모양 -> 프리팹에는 Destroyer 스크립트 연결되있음(애니메이션 마지막 부부분에서 자기자신을 삭제해줌)
플레이어 제거
ReloadGame 코루틴 실행
IEnumerator ReloadGame()
{
// ... pause briefly
yield return new WaitForSeconds(2);
// ... and then reload the level.
Application.LoadLevel(Application.loadedLevel);
}
2초후 게임 다시 실행
'잡다한것들전부 > 공식예제' 카테고리의 다른 글
| 폭탄과 구급 상자 - Bomb Pickup, Bomb (0) | 2014.02.25 |
|---|---|
| 물체 파괴 함수 -> Destroyer 스크립트 (0) | 2014.02.25 |
| killTrigger -> 모든 적과 주인공 충돌(강) - Removver 스크립트 (0) | 2014.02.25 |
| 플레이어의 체력 - PlayerHealth (0) | 2014.02.25 |
| 플레이어 무기 발사 - gun 스크립트 (0) | 2014.02.25 |
| 주인공을 따라다니는 카메라 (0) | 2014.02.25 |


