-
게임개발 15일차 (Unity Learn 5일차)게임 개발 2025. 6. 11. 15:44
애니메이터에는 레이어와 패러미터가 있다.
오브젝트는 레이어마다 하나의 상태에 있어야 한다.
ex) 걷기-달리기 and 점프-땅
달리기 상태이면서 점프상태여야 하는것.
패러미터로 애니메이션의 방향을 정할 수 있다.
ex) 죽을 때 DeathType_int가 1인지 2인지에 따라서 애니메이션이 2개로 나뉨
private Animator playerAnim;
playerAnim.SetBool("Death_b", true); // 생존여부
playerAnim.SetInteger("DeathType_int", 1); // 죽음 애니메이션 선택Animator를 가져온 후 죽게 만들면서 뒷 방향으로 죽게 만든 코드이다.
SetTrigger로 상태를 바꿀 수도 있고 저렇게 패러미터로 상태를 바꿀수도 있다.
특수효과도 넣었다. 달리는 특수효과와 죽음 특수효과
public ParticleSystem explosionParticle;
public ParticleSystem dirtParticle;void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && isOnGround && !gameOver)
{
dirtParticle.Stop(); // 게임오버아니고 땅에 있을 때 스페이스 누르면 달리기 특수효과가 멈춤}
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Ground"))
{
dirtParticle.Play(); // 다시 땅에 닿으면 특수효과
}
else if (collision.gameObject.CompareTag("Obstacle"))
{
explosionParticle.Play(); // 폭발일으키고
dirtParticle.Stop(); // 달리는특수효과 끔
}
}
음향도 넣었다.
private AudioSource playerAudio; // 오디오소스 변수 미리 선언
start
playerAudio = GetComponent<AudioSource>(); // 오디오 소스를 스크립트에 연결
점프누름
playerAudio.PlayOneShot(jumpSound, 1.0f); // 점프사운드 재생 (한번만)
Update{
if (transform.position.y < lowBound)
{
playerRb.AddForce(Vector3.up * floatForce, ForceMode.Impulse);
playerAudio.PlayOneShot(boingSound, 1.5f);
}}풍선게임에서 일정 아래로 내려가면 위로 힘을 주도록 했지만 이러면 날아가버렸다. (프레임마다 힘을 줘버림)
private void OnCollisionEnter(Collision other)
else if (other.gameObject.CompareTag("Ground"))
{
playerRb.AddForce(Vector3.up * 0.5f * floatForce, ForceMode.Impulse);
playerAudio.PlayOneShot(boingSound, 1.5f);
}충돌 시 힘을 주도록 해야 딱 한번 힘을 준다.
'게임 개발' 카테고리의 다른 글
게임개발 17일차 (Unity Learn 7일차) (0) 2025.06.13 게임개발 16일차 (Unity Learn 6일차) (0) 2025.06.12 게임개발 14일차 (Unity Learn 4일차) (2) 2025.06.10 게임개발 13일차 (Unity Learn 3일차) (1) 2025.06.08 게임개발 12일차 (Unity Learn 2일차) (0) 2025.06.07