public void Update() { if (_timer && _endTime < Time.time) { _timer = false; explosive.Explode(); } }
public void Fire() { if (ammo >= 1) { ammo--; //if ammo is 0, disable the turret if (ammo <= 0) { DisableTurret(); } fired = true; if (timer >= timeBetweenBullets) { // Reset the timer. timer = 0f; // Play the gun shot audioclip. // gunAudio.Play(); // Enable the light. gunLight.enabled = true; // Stop the particles from playing if they were, then start the particles. gunParticles.Stop(); gunParticles.Play(); // Enable the line renderer and set it's first position to be the end of the gun. gunLine.enabled = true; gunLine.SetPosition(0, transform.position); // Set the shootRay so that it starts at the end of the gun and points forward from the barrel. shootRay.origin = transform.position; shootRay.direction = transform.forward; // Perform the raycast against gameobjects on the shootable layer and if it hits something... if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { // Try and find an EnemyHealth script on the gameobject hit. Explosive explosive = shootHit.collider.GetComponent <Explosive>(); // Set the second position of the line renderer to the point the raycast hit. gunLine.SetPosition(1, shootHit.point); // If the Explosive component exist... if (explosive != null) { explosive.Explode(shootHit.point); } } // If the raycast didn't hit anything on the shootable layer... else { print("hit nothing"); // ... set the second position of the line renderer to the fullest extent of the gun's range. gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } } } }
private IEnumerator DoExplode() { yield return(new WaitForSeconds(explosionDelay)); explosive.Explode(); Destroy(gameObject, 0); }
void OnCollisionEnter(Collision collision) { if (collision.impulse.magnitude > explodeThreshold) { explosive.Explode(); } }
public void CreateExplosion(Vector2 pos, float force, float range, float upwards) { var targets = GetRigidbodiesInRange(pos, range); foreach (Rigidbody2D r in targets) { Debug.Log(r); if (!r.gameObject.Equals(gameObject)) { if (r.gameObject.GetComponent <Explosive>() != null) { Debug.Log("Shit should work!"); Explosive explode = r.gameObject.GetComponent <Explosive>(); if (!explode.isDone() && explode.isActive()) { explode.Explode(); } } else { r.AddExplosionForce(force, pos, range, upwards); } } } }
protected virtual void Impact(Collision collisionData) { if (collisionData != null) { string output = ""; if (Owner != null) { if (!CanHitOwner) { if (collisionData.gameObject == Owner.gameObject) { Debug.Log(name + " can't hit owner " + Owner.name); return; } } output += Owner.name + " with "; } output += name; //Debug.Log(collisionData.gameObject.name + " was hit by " + output); Player playerHit = collisionData.gameObject.GetComponent <Player>(); if (playerHit != null) { //player.TakeDamage(Damage); if (Owner != null) { GameManager.Instance.PlayerTakesDamage(playerHit, Damage, Owner); } else { GameManager.Instance.PlayerTakesDamage(playerHit, Damage); } //player.Die(); } Health healthComponent = collisionData.collider.GetComponentInParent <Health>(); if (healthComponent != null) { healthComponent.UpdateValue(healthComponent.value - Damage); } } impactPosition = transform.position; hasImpacted = true; Explosive explosive = GetComponent <Explosive>(); if (explosive != null) { explosive.Explode(); } if (DisappearUponImpact) { if (ServerBehaviour.HasActiveInstance()) { ServerBehaviour.Instance.SendProjectileImpact(this); } //Debug.Log("Disappear"); gameObject.SetActive(false); } }
public Explosive bomb; // link to the bomb we trigger // New Function: // OnTriggerEnter() // - If this script is attached to a game object that has a trigger, // this function will get called every time something enters the trigger void OnTriggerEnter() { // something has entered the trigger // make the bomb explode bomb.Explode(); // single-use, destroy ourselves Destroy(gameObject); }
/// <summary> /// Find the best target and turn the missile for a head-on collision. /// </summary> void Update() { float time = Time.time; if (mNextUpdate < time) { mNextUpdate = time + updateFrequency; // Find the most optimal target ahead of the missile if (currentTarget == null || !oneTarget) { currentTarget = HeatSource.Find(mTrans.position, mTrans.rotation * Vector3.forward, sensorRange, sensorAngle); } if (currentTarget != null) { // Calculate local space direction Vector3 dir = (currentTarget.transform.position - mTrans.position); float dist = dir.magnitude; dir *= 1.0f / dist; dir = Quaternion.Inverse(mTrans.rotation) * dir; // Make the missile turn slower if it's far away from the target, and faster when it's close float turnSensivitity = 0.5f + 2.5f * (1.0f - dist / sensorRange); // Calculate the turn amount based on the direction mTurn.x = Mathf.Clamp(dir.y * turnSensivitity, -1f, 1f); mTurn.y = Mathf.Clamp(dir.x * turnSensivitity, -1f, 1f); // Locked on target mTimeSinceTarget = 0f; } else { // No target lock -- keep track of how long it has been mTimeSinceTarget += updateFrequency + Time.deltaTime; } mControl.turningInput = mTurn; mControl.moveInput = Vector3.forward; } // If it has been too long if (mTimeSinceTarget > 2f) { Explosive exp = mControl.GetComponentInChildren <Explosive>(); if (exp != null) { exp.Explode(); } else { NetworkManager.RemoteDestroy(mControl.gameObject); } } }
/// <summary> /// name on tin /// </summary> /// <returns></returns> public IEnumerator Explode() { _audio.PlayOneShot(_audio.clip); yield return(new WaitForSeconds(_explosionDelay)); explosion.Explode(); yield return(new WaitForSeconds(0.1f)); //delete self here }
public void Die() { if (explosive != null) { explosive.Explode(); } else { Destroy(gameObject); } }
public Explosive bomb; // link to the bomb we trigger // New Function: // OnTriggerEnter() // - If this script is attached to a game object that has a trigger, // this function will get called every time something enters the trigger void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Player")) { // something has entered the trigger // make the bomb explode bomb.Explode(); // single-use, destroy ourselves Destroy(gameObject); } }
public void Destroy() { Explosive explosive = GetComponent <Explosive> (); if (explosive != null) { explosive.Explode(); } gameController.AddScore(points); Destroy(gameObject); }
public void Detonate() { foreach (ParticleSystem ps in explosionParticles) { ps.Play(); } AudioControl audioControl = GameController.instance.GetAudio(); if (audioControl != null) { audioControl.SfxPlay(2); } detonated = true; Collider[] colliders = Physics.OverlapSphere(transform.position, explosionRadius); foreach (Collider c in colliders) { StorageSystem storage = c.GetComponent <StorageSystem>(); if (storage != null) { List <GameObject> items = storage.RemoveAllContents(); foreach (GameObject storageItem in items) { Rigidbody sirb = storageItem.GetComponent <Rigidbody>(); if (sirb != null) { sirb.AddExplosionForce(explosionForce, transform.position, explosionRadius); } Explosive storageItemExplosive = storageItem.GetComponent <Explosive>(); if (storageItemExplosive != null) { storageItemExplosive.Explode(); } } } Rigidbody cRB = c.gameObject.GetComponent <Rigidbody>(); if (cRB != null) { cRB.AddExplosionForce(explosionForce, transform.position, explosionRadius); } Explosive colliderExplosive = c.gameObject.GetComponent <Explosive>(); if (colliderExplosive != null) { colliderExplosive.shouldExplode = true; } } try { GameController.instance.showGameOverUI(); } catch (Exception e) { Debug.Log(e); } }
/// <summary> /// When the plasma beam hits something we want to apply damage and destroy the beam. /// </summary> void OnTriggerEnter(Collider col) { if (!mIsMine) { return; } Rigidbody rb = Tools.FindInParents <Rigidbody>(col.transform); if (rb != null) { Explosive exp = rb.GetComponentInChildren <Explosive>(); if (exp != null) { exp.Explode(); } else { Rigidbody myRb = rigidbody; if (myRb != null) { Vector3 force = myRb.velocity * myRb.mass * forceOnCollision; Vector3 pos = transform.position; NetworkRigidbody nrb = NetworkRigidbody.Find(rb); if (nrb != null) { nrb.AddForceAtPosition(force, pos); } } } } // Apply damage to the unit, if we hit one GameUnit unit = Tools.FindInParents <GameUnit>(col.transform); if (unit != null) { unit.ApplyDamage(damageOnHit); } // Destroy this beam NetworkManager.RemoteDestroy(gameObject); }
// Metoda odpowiedzialna za eksplozję granatu void Explode() { audioSource.PlayOneShot(explosion); // Odtwarza dźwięk eksplozji particle.Emit(particleQuantity); // Emituje cząsteczki w ilości równej wartości zminnej particleQuantity GetComponent <MeshRenderer>().enabled = false; // Wyłącza renderer granata, przez co ten po wybuchu nie jest widoczny GetComponent <SphereCollider>().enabled = false; // Wyłącza collider granata, by po wybuchu nie kolidował z innymi obiektami hasExploded = true; // Zapobiega kilkukrotnemu wybuchowi granata Collider[] colliders = Physics.OverlapSphere(transform.position, radius); //Tworzy sferę pobierającą wszystkie obiekty wewnątrz niej foreach (Collider nearbyObject in colliders) { Rigidbody rb = nearbyObject.GetComponent <Rigidbody>(); if (rb != null) { if (rb.tag == "Enemy") //Jeżeli obiekt w obszarze wybuchu to przeciwnik, to na jedną sekundę wyłączany jest NavMeshAgent, wartość zmiennej //isKinematic ustawiana jest na false po to, by obiekt został właściwie odrzucony przez wybuch oraz zadawane są obrażenia { EnemyMovement enemyMovement = rb.GetComponent <EnemyMovement>(); enemyMovement.StopNav(); enemyMovement.MakeNonKinematic(); enemyMovement.Invoke("MakeKinematic", 1); enemyMovement.Invoke("StartNav", 1); Enemy enemy = rb.GetComponent <Enemy>(); enemy.Hit(damage); } if (rb.tag == "Player") //Jeżeli obiekt w obszarze wybuchu to gracz, to zadawane są mu obrażenia. { Player player = rb.GetComponent <Player>(); player.Hit(transform, false); } if (rb.tag == "Barrel") //Jeżeli obiekt w obszarze wybuchu to beczka, to wywołana zostaje jej eksplozja { Explosive explosive = rb.GetComponent <Explosive>(); explosive.Explode(); } rb.AddExplosionForce(force, transform.position, radius); //Dodawana jest siła odrzucająca obiekt od środka wybuchu zależnie od odległości od środka i wartości zmiennej force } } Destroy(gameObject, 2f); //Po dwóch sekundach od wybuchu niszczony jest obiekt. Niszcząc obiekt od razu, //usunięte zostałyby cząsteczki po wybuchu oraz zachowanie przeciwników nie zostałoby przywrócone }
public void Destroy() { foreach (FaceType face in faceTypes) { if (face != null) { face.Destroy(); } } bossController.RemoveFromBodyComponentList(location); gameController.AddScore(points); Explosive explosive = GetComponent <Explosive> (); if (explosive != null) { explosive.Explode(); } Destroy(gameObject); }
public override void Kill() { //Collider2D[] cols = Physics2D.OverlapCircleAll(transform.position, damageRadius); //for (int i = 0; i < cols.Length; i++) //{ // if (cols[i].gameObject == this.gameObject) // continue; // Rigidbody2D rb = cols[i].GetComponent<Rigidbody2D>(); // if (rb == null) // continue; // Vector3 dir = (rb.transform.position - transform.position).normalized; // rb.AddForce(dir * knockBack, ForceMode2D.Impulse); // HasHealth health = rb.GetComponent<HasHealth>(); // if (health != null) // { // if (cols[i].tag == "Player") // health.Damage(damagePlayer); // else // health.Damage(damageEnemy); // } //} isDead = true; bomb.Explode(this); }
/// <summary> /// Restore the physics collision or destroy the fired object if enough time has passed. /// </summary> void Update() { float time = Time.time; if (mIgnoredColliders != null && time - mSpawnTime > 1f) { IgnoreColliders(false); mIgnoredColliders = null; } if (time > mDestroyTime) { Explosive exp = GetComponentInChildren <Explosive>(); if (exp != null) { exp.Explode(); } else { NetworkManager.RemoteDestroy(gameObject); } } }
public override void Die() { explosive.Explode(); base.Die(); }
public void Shoot() { UpdateAmmoUI(); // Reset the timer. timer = 0f; // Play the gun shot audioclip. aSource.PlayOneShot(shootClip); // Enable the light. gunLight.enabled = true; // Stop the particles from playing if they were, then start the particles. if (playerType == PlayerType.Player1) { GameObject muzzle = Instantiate(muzzlePrefab, muzzleStart.position, muzzleStart.rotation); ParticleSystem mz = muzzle.GetComponent <ParticleSystem>(); mz.Stop(); mz.Play(); } else { gunParticles.Stop(); gunParticles.Play(); } // Enable the line renderer and set it's first position to be the MUZZLE. gunLine.enabled = true; gunLine.SetPosition(0, muzzleStart.position); // Set the shootRay so that it starts at the end of the gun and points forward from the barrel. shootRay.origin = firePoint.position; shootRay.direction = firePoint.forward; // Perform the raycast against gameobjects on the shootable layer and if it hits something... if (Physics.Raycast(shootRay, out shootHit, range, Physics.DefaultRaycastLayers, QueryTriggerInteraction.Ignore)) { // Try and find an EnemyHealth script on the gameobject hit. print("ray hit " + shootHit.collider.gameObject.name); EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>(); // If the EnemyHealth component exist... if (enemyHealth != null) { // print("enemy found" + enemyHealth.gameObject.name); // ... the enemy should take damage. enemyHealth.TakeDamage(damagePerShot); // print("enemy damage called"); } else { Explosive explosive = shootHit.collider.GetComponent <Explosive>(); if (explosive) { explosive.Explode(shootHit.point); } } // Set the second position of the line renderer to the point the raycast hit. gunLine.SetPosition(1, shootHit.point); } // If the raycast didn't hit anything on the shootable layer... else { // ... set the second position of the line renderer to the fullest extent of the gun's range. gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } }