public void FireClustershot() { float rotationRangeMin = scattershotAmt / 2f - scattershotAmt; float rotationRangeMax = scattershotAmt / 2f; for (int i = 0; i < scattershotAmt; i++) { GameObject clustershotInstance = Instantiate(scattershot); CannonballScript ballInfo = cannonball.GetComponent <CannonballScript>(); ballInfo.Source = SpawnSource.Player; ballInfo.Lifetime = cannonballLifetime; ballInfo.Damage = damagePerScattershot; clustershotInstance.transform.position = transform.position; clustershotInstance.transform.rotation = transform.rotation; Rigidbody rigidbody = clustershotInstance.GetComponent <Rigidbody>(); if (_shipRb != null) { rigidbody.velocity = _shipRb.velocity; } float spread = Random.Range(rotationRangeMin, rotationRangeMax); clustershotInstance.transform.Rotate(new Vector3(0f, spread * rotationFactor, 0f)); if (isRight) { rigidbody.AddRelativeForce(new Vector3(0f, Random.Range(minScatterSpread, maxScatterSpread), -scattershotSpeed)); } else { rigidbody.AddRelativeForce(new Vector3(0f, Random.Range(minScatterSpread, maxScatterSpread), scattershotSpeed)); } } for (int i = 0; i < _particles.Length; i++) { _particles[i].Play(); } _audioSource.clip = _cannonSounds[Random.Range(0, _cannonSounds.Length - 1)]; _audioSource.Play(); _cooldownTimer = cooldown; _hasFired = true; }
private void OnCollisionEnter(Collision collision) { if (collision.gameObject.tag == "Player") { //health.TakeDamage(20); } else if (collision.gameObject.tag == "Cannonball") { CannonballScript ball = collision.gameObject.GetComponent <CannonballScript>(); if (ball.Source == SpawnSource.Player) { health.TakeDamage(20); Destroy(collision.gameObject); } else { //print("Friendly fire you c**t"); } } }
public void Fire(Vector3 shipVelocity) { GameObject cannonballInstance = Instantiate(cannonball); CannonballScript ballInfo = cannonball.GetComponent <CannonballScript>(); ballInfo.Source = SpawnSource.EnemyHeavyWarship; ballInfo.Lifetime = cannonballLifetime; cannonballInstance.transform.position = transform.position; cannonballInstance.transform.rotation = transform.rotation; Rigidbody rigidbody = cannonballInstance.GetComponent <Rigidbody>(); if (isRight) { rigidbody.AddRelativeForce(new Vector3(0, 0, -cannonballSpeed) + shipVelocity); } else { rigidbody.AddRelativeForce(new Vector3(0, 0, cannonballSpeed) + shipVelocity); } }
public void FireCannonball() { GameObject cannonballInstance = Instantiate(cannonball); CannonballScript ballInfo = cannonball.GetComponent <CannonballScript>(); ballInfo.Source = SpawnSource.Player; ballInfo.Lifetime = cannonballLifetime; ballInfo.Damage = damagePerCannonball; cannonballInstance.transform.position = transform.position; cannonballInstance.transform.rotation = transform.rotation; Rigidbody rigidbody = cannonballInstance.GetComponent <Rigidbody>(); if (_shipRb != null) { rigidbody.velocity = _shipRb.velocity; } if (isRight) { rigidbody.AddRelativeForce(new Vector3(0, 0, -cannonballSpeed)); } else { rigidbody.AddRelativeForce(new Vector3(0, 0, cannonballSpeed)); } for (int i = 0; i < _particles.Length; i++) { _particles[i].Play(); } _audioSource.clip = _cannonSounds[Random.Range(0, _cannonSounds.Length - 1)]; _audioSource.Play(); _cooldownTimer = cooldown; _hasFired = true; }