void Fire(float spread = 0f, float speed = 0f) { GameObject b = bulletPool.GetObject(); MetaAsteroids_Bullet bullet = b.GetComponent <MetaAsteroids_Bullet>(); Vector3 forward = -transform.right; forward += transform.up * Random.Range(-1f, 1f) * spread; bullet.Shoot( transform.position - transform.right * BulletSpawnDistance, forward.normalized, speed, playerAsteroids ); }
void OnCollisionEnter2D(Collision2D col) { MetaAsteroids_Asteroid asteroid = col.gameObject.GetComponent <MetaAsteroids_Asteroid>(); if (asteroid != null && asteroid.gameObject.activeSelf) { OnHitAsteroid(); } else { MetaAsteroids_Bullet bullet = col.gameObject.GetComponent <MetaAsteroids_Bullet>(); if (bullet != null && bullet.gameObject.activeSelf) { OnHitByBullet(); } } }