-
void OnTriggerEnter(Collider other) { .....(중간 생략) else if (other.tag=="EnemyBullet"){ if (!isDamage){ Bullet.EnemyBullet = other.GetComponent<Bullet>(); health -= EnemyBullet.damage; StartCoroutine(OnDamage()); //리액션 취하기 } } }
위에서 OnTriggerEnter으로 플레이어 로직에서 플레이어 객체가 상대로 정해진 EnemyBullet을 만나면 데미지를 입도록 설정. isDamage라는 bool값을 미리 선언해서 true로 해놓고, 데미지를 입으면 그 객체가 가진 데미지만큼 플레이어의 현재 체력을 깎고, Coroutine을 통해 데미지 입히는 색상 변경을 설정.
IEnumerator OnDamage(){ isDamage = true; foreach(MeshRenderer mesh in meshs){ mesh.material.color = Color.red; } yield return new WaitForSeconds(If); isDamage = false; foreach(MeshRenderer mesh in meshs){ mesh.material.color = Color.white; } }
색깔을 변경하도록 설정.
'개발 > Unity' 카테고리의 다른 글
유니티(Unity)_particle 특수 효과. 파티클 이펙트 (0) 2021.05.21 유니티(Unity)_애니매이션 속도 조절, 몬스터 속도 조절 (0) 2021.05.21 유니티(Unity)_Navigation에서 물체가 선택되지 않을 때. (0) 2021.04.13 유니티(Uinity)_Failed to create agent because there is no valid NavMesh 오류 해결 (0) 2021.04.13 유니티(Unity)_자주 까먹는 설정. 기본 밝기 설정. 빛 설정. (0) 2021.04.08 댓글 (비로그인 댓글 허용하지 않습니다.)