상자는 나머지를 보관한다
Coddy Unity 여정의 물리와 게임플레이 섹션에 포함된 레슨. 71개 중 18번째.
챌린지
쉬움상자에 들어가지 않은 탄약은 상자에 남겨 두세요.
AmmoCrate.cs에서AddAmmo줄을amount -= blaster.AddAmmo(amount);로 바꾸세요.amount == 0일 때만Destroy(gameObject);를 호출하세요.
‘플레이’를 누르고 오른쪽으로 걸어가세요. Crate2는 들어가지 않은 2개를 담은 채 남아 있습니다. 그런 다음 ‘확인’을 누르세요.
직접 해보기
using UnityEngine;
public class AmmoCrate : MonoBehaviour
{
public int amount = 3;
void OnTriggerEnter(Collider other)
{
if (other.TryGetComponent(out Blaster blaster))
{
blaster.AddAmmo(amount);
Destroy(gameObject);
}
}
}
물리와 게임플레이의 모든 레슨
직접 연습해 보세요: Unity 플레이그라운드