void Fire(Vector3 direction) { fireSound.Play(); int damage = 5; if (QuadDamageTimer.Value > Time.time) { damage = 20; } bool bounce = BounceTimer.Value > Time.time; GameObject bullet = m_ObjectPool.GetNetworkObject(BulletPrefab); bullet.transform.position = transform.position + direction; var bulletRb = bullet.GetComponent <Rigidbody2D>(); Vector2 velocity; velocity = m_Rigidbody2D.velocity; velocity += (Vector2)(direction) * 10; bulletRb.velocity = velocity; bullet.GetComponent <Bullet>().Config(this, damage, bounce, bulletLifetime, m_ObjectPool); bullet.GetComponent <NetworkObject>().Spawn(null, true); }
public void Explode() { Assert.IsTrue(NetworkManager.IsServer); numAsteroids -= 1; var newSize = Size.Value - 1; if (newSize > 0) { int num = Random.Range(1, m_NumCreates + 1); for (int i = 0; i < num; i++) { int dx = Random.Range(0, 4) - 2; int dy = Random.Range(0, 4) - 2; Vector3 diff = new Vector3(dx * 0.3f, dy * 0.3f, 0); var go = m_ObjectPool.GetNetworkObject(NetworkObject.PrefabHash, transform.position + diff, Quaternion.identity); go.GetComponent <Asteroid>().Size.Value = newSize; go.GetComponent <NetworkObject>().Spawn(); go.GetComponent <Rigidbody2D>().AddForce(diff * 10, ForceMode2D.Impulse); } } NetworkObject.Despawn(); m_ObjectPool.ReturnNetworkObject(NetworkObject); }
void SpawnAsteroids() { for (int i = 0; i < m_Amount; i++) { GameObject go = m_ObjectPool.GetNetworkObject(m_AsteroidPrefab); go.transform.position = new Vector3(Random.Range(-40, 40), Random.Range(-40, 40)); go.transform.localScale = new Vector3(4, 4, 4); go.GetComponent <Asteroid>().Size.Value = 4; float dx = Random.Range(-40, 40) / 10.0f; float dy = Random.Range(-40, 40) / 10.0f; float dir = Random.Range(-40, 40); go.transform.rotation = Quaternion.Euler(0, 0, dir); go.GetComponent <Rigidbody2D>().angularVelocity = dir; go.GetComponent <Rigidbody2D>().velocity = new Vector2(dx, dy); go.GetComponent <NetworkObject>().Spawn(null, true); } }