private void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("Player's Bullet")) { Bullet_Player bullet = collision.GetComponent <Bullet_Player>(); bullet.OnCollisionWithTarget(); health -= bullet.damage; Knockback(bullet.knockbackForce); if (health <= 0) { Die(); } } }
protected GameObject ShootBullet(string name) { Vector2 dir = GameManager.Ins.RotateDirection(aim, UnityEngine.Random.Range(-spread, spread)); GameObject bulletObj = ObjectPool.Ins.PopFromPool(name, muzzle.position); bulletObj.GetComponent <Rigidbody2D>().velocity = dir * bulletSpeed; Bullet_Player bullet = bulletObj.GetComponent <Bullet_Player>(); bullet.damage = bulletDamage; bullet.knockbackForce = dir * bulletKnockback; bullet.disposeSec = disposingSec; return(bulletObj); }