Unity_beginner #13
210712
unity_beginner #13
지난번의 OnCollisionEnter는 두 물체간 충돌이 발생했을 때 실행
- Trigger
충돌은 발생하진 않지만 물체가 특정 영역을 지나갔다는 것을 Trigger라고 함
Ball 게임에서 영역을 벗어난 경우 실패조건에 추가한다고 하면?
-FailZone 제작
Mash Renderer를 체크해제 해줌으로써 보이지 않게
is Trigger에 체크를 해제하면 collider가 작동하여 위에서 구르지 않고 영역을 지났는지 체크만 할 수 있다.
FailZone을 지났는지 체크를 하기 위해 FailZone에 script를 추가한다.
-OnTriggerEnter를 사용
OnCollisionEnter에서는 매개변수가 Collision이었으나 OnTriggerEnter에서는 매개변수가 Collider이다
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FailZone : MonoBehaviour
{
void OnTriggerEnter(Collider collider)
{
if(collider.gameObject.name == "Ball") // Ball이라는 오브젝트인 경우
{
Application.LoadLevel("Game"); // unity파일을 저장할 때 Game이라는 이름으로 저장했기 때문
// "Game" 판을 다시 시작한다
}
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
-떨어지게되면 판을 새로 시작하는 것을 확인할 수 있다.
참고
https://programmers.co.kr/learn/courses/1/lessons/678#note
Author And Source
이 문제에 관하여(Unity_beginner #13), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@kimhaech/Unitybeginner-13저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)