유니티/AA(3D 쿼터뷰 액션 게임)
AA(13) - 소모아이템 획득
무직백수취업준비생
2021. 9. 14. 03:27
728x90
반응형
public int ammo;
public int coin;
public int health;
public int hasGrenade;
public int maxAmmo;
public int maxCoin;
public int maxHealth;
public int maxHasGrenade;
소비 아이템들과 그 최댓값의 변수 선언부터 해줍니다.
기본값과 최대값을 설정해줍니다.
void OnTriggerEnter(Collider other)
{
if(other.tag == "Item")
{
Item item = other.GetComponent<Item>();
switch (item.type)
{
case Item.Type.Ammo:
ammo += item.value;
if (ammo > maxAmmo)
ammo = maxAmmo; //최대치 초과시 수치는 최대값과 동일
break;
case Item.Type.Coin:
coin += item.value;
if (coin > maxCoin)
coin = maxCoin;
break;
case Item.Type.Heart:
health += item.value;
if (health > maxHealth)
health = maxHealth;
break;
case Item.Type.Grenade:
hasGrenade += item.value;
if (hasGrenade > maxHasGrenade)
hasGrenade = maxHasGrenade;
break;
}
Destroy(other.gameObject); //접촉한 소모아이템 파괴
}
}
Coin과 Ammo와 접촉하여 파괴하고 캐릭터의 수치가 오른 걸 확인할 수 있습니다.
728x90
반응형