this.rBody2D.velocity = this.dir.normalized * this.speed * Time.deltaTime * this.knockbackSpeed;
protected void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("PlayerBullet"))
{
StartCoroutine(KnockbackRoutine(collision.GetComponent<Bullet>().knockbackSpeed));
}
}
protected IEnumerator KnockbackRoutine(float knockbackSpeed)
{
this.knockbackSpeed = -knockbackSpeed;
yield return new WaitForSeconds(0.1f);
this.knockbackSpeed = 1f;
}
오브젝트의 기존 이동 방향에서 -방향으로 이동하게끔 구현하였다.
'Unity2D' 카테고리의 다른 글
Unity) [유니티 2D] Enemy Generator(적 생성) 구현 (0) | 2023.03.18 |
---|---|
Unity) [유니티 2D] Skill(Spell) Indicator 구현 (0) | 2023.03.14 |
Unity) [유니티 2D] 플레이어 대시, 잔상 구현 (0) | 2023.03.10 |
Unity) [유니티 2D] A* PathFinder 기반 원거리 적 구현 (0) | 2023.03.10 |
Unity) [유니티 2D] A* PathFinder 스크립트 커스터마이징 (0) | 2023.03.10 |