/* * void HitDummy(Collider other, int dmg, Vector3 force) * { * TargetDummy targetDummy = other.gameObject.GetComponent<TargetDummy>(); // Target dummy for testing * if (targetDummy != null) * { * // Deal damage * targetDummy.TakeDamage(dmg, force); * * // Hp drops to 0 after taking damage * if (targetDummy.currentHealth <= 0) * { * parentScript.PlayHitSounds(true); * } * else * { * parentScript.PlayHitSounds(false); * } * } * } */ // old way of creating explosion. spawns sphere and collider of that sphere is used for hit detection void Explosion(GameObject direct) { // Spawn explosion var explosion = (GameObject)Instantiate(explosionPrefab, transform.position, transform.rotation); // Explosion stats ProjectileExplosion explosionScript = explosion.GetComponent <ProjectileExplosion>(); explosionScript.splashDamage = splashDamage; explosionScript.knockbackForce = knockbackForce; // Link parent script explosionScript.parentScript = parentScript; // Link player gameobject explosionScript.parentGameObject = parentGameObject; // Player that got hit directly explosionScript.directHit = direct; // Spawn the explosion on the Clients // No need to do this since projectiles are client side after spawning? //NetworkServer.Spawn(projectile); // Destroy the explosion after x seconds Destroy(explosion, 0.25f); }
IEnumerator ShootingCheck() { while (true) { if (Input.GetKey(KeyCode.Space) == true || Input.GetKeyDown(KeyCode.Space) == true) { GameObject bullet = Instantiate(Bullet, bulletSpawn.position, bulletSpawn.rotation) as GameObject; Rigidbody2D bulletRb2d = bullet.GetComponent <Rigidbody2D> (); bulletRb2d.velocity = shipRb2d.velocity; bulletRb2d.AddForce(bulletSpawn.up * bulletSpeed); ProjectileExplosion explo = bullet.GetComponent <ProjectileExplosion> (); explo.Damage = damage; explo.Knockback = knockBack; explo.Stun = stun; explo.Invoke("Explode", lifespan); yield return(new WaitForSeconds(fireWait)); continue; } yield return(null); } }
void OnTriggerEnter2D(Collider2D other) { if (LayerMask.LayerToName(other.gameObject.layer) == "PlayerProjectiles") { ProjectileExplosion explo = other.GetComponent <ProjectileExplosion> (); bulletDamage = explo.Damage; damageDone = bulletDamage - armor; health -= damageDone; percentHealth = health / totalHealth; if (rb2d != null) { bulletKnockback = explo.Knockback; knockBackDirection = other.transform.up; rb2d.AddForce(knockBackDirection * bulletKnockback); } if (damageDone > 0) { HealthBar.localScale = new Vector3(percentHealth, HealthBar.localScale.y, HealthBar.localScale.z); HealthBar.position = new Vector3(HealthBar.position.x - ((damageDone / totalHealth) / 2), HealthBar.position.y, HealthBar.position.z); } Destroy(other.gameObject); } }
IEnumerator Shoot() { while (true) { if (target != null) { if (LOS == true) { bullet = (GameObject)Instantiate(Bullet, bulletSpawn.position, bulletSpawn.rotation); bullet.transform.parent = transform; bullet.GetComponent <Rigidbody2D>().AddForce(direction * bulletSpeed); ProjectileExplosion explo = bullet.GetComponent <ProjectileExplosion>(); explo.Damage = damage; explo.Knockback = knockBack; explo.Stun = stun; explo.Invoke("Explode", lifespan); yield return(new WaitForSeconds(fireWait)); } else { yield return(null); } } else { GetComponent <LineRenderer>().enabled = false; yield return(null); } } }
IEnumerator Shoot() { GameObject laser = Instantiate(Projectile, Shooter.position, transform.rotation) as GameObject; laser.transform.RotateAround(laser.transform.position, laser.transform.forward, -90f); laser.transform.Translate(Vector3.forward); ProjectileExplosion explo = laser.GetComponent <ProjectileExplosion> (); explo.Damage = Damage; explo.Knockback = Knockback; explo.Stun = Stun; explo.Invoke("Explode", Lifespan); Rigidbody2D laserRb2d = laser.GetComponent <Rigidbody2D> (); laserRb2d.velocity = rb2d.velocity; laserRb2d.AddForce(new Vector2(laser.transform.up.x, laser.transform.up.y) * ShotSpeed); ShootReady = false; yield return(new WaitForSeconds(ShootCooldown)); ShootReady = true; }
private Task ProjectileExplode() { if (debug) { Console.WriteLine($"OBSERVER: NetworkManagerClient ProjectileExpode"); } ProjectileExplosion?.Invoke(); return(Task.CompletedTask); }
public virtual void Start() { #endif body = GetComponent <Rigidbody>(); projectile_explosion = new ProjectileExplosion(); }
public virtual void Start() { #endif rising = true; projectile_explosion = new ProjectileExplosion(); }
public virtual void Start() { #endif projectile_explosion = new ProjectileExplosion(); }