private void OnCollisionEnter2D(Collision2D collision)
{
var bullet = collision.collider.GetComponent<Bullet>();
var skill = collision.collider.GetComponent<PlayerActiveSkill>();
//if(this.knockBackRoutine != null) this.StopCoroutine(this.knockBackRoutine);
if (collision.collider.CompareTag("PlayerBullet"))
{
if (bullet != null)
{
//탄환의 진행 방향으로 넉백
this.knockbackDir = bullet.dir;
this.knockBackRoutine = this.StartCoroutine(this.KnockbackRoutine());
this.knockBackSpeed = bullet.knockbackSpeed;
bullet.penetrateCnt--;
if (bullet.penetrateCnt <= 0) Destroy(bullet.gameObject);
this.monster.TakeBulletDamage(bullet.damage);
Physics2D.IgnoreCollision(collision.collider, GetComponent<Collider2D>());
}
}
}
palyerBullet이 가진 스크립트에서 관통횟수를 확인하여 해당 횟수를 감산하는 식으로 구현하면 쉽지만 한번 관통된 탄환은 몬스터와 다시 물리작용되지 않도록 Physics2D.IgnoreCollision(collision.collider, GetComponent<Collider2D>()); 해당 기능을 사용해야한다.
'Unity2D' 카테고리의 다른 글
Unity) [유니티 2D] 돌진 공격 구현 (0) | 2023.04.17 |
---|---|
Unity) [유니티 2D] 3갈래로 탄환을 발사하는 몬스터 구현 (0) | 2023.04.17 |
Unity) [유니티 2D] Physics2D.IgnoreLayerCollision 기능을 사용하여 자연스러운 넉백 효과 만들기 (0) | 2023.04.15 |
Unity) [유니티 2D] 슈터게임 여러 갈래의 탄환 구현 (0) | 2023.04.14 |
Unity) [유니티 2D] 3갈래로 발사되는 탄환, 총알 구현 (0) | 2023.04.14 |