private void DestroyProjectile(Core_Projectile projectile) { projectileList.Remove(projectile); if (projectile != null) { Destroy(projectile.gameObject); } }
private void ManageProjectileList() { if (projectileList.Count > 0) { for (int i = 0; i < projectileList.Count; i++) { Core_Projectile projectile = projectileList[i]; if (Time.time >= (projectile.GetSpawnTime() + projectile.GetLifeTime())) { DestroyProjectile(projectile); i--; } } } }
public void OnProjectileTriggerEnter(Core_Projectile projectile, GameObject collidedObject) { //Check which object collided with //If enemy ship, damage enemyShip //Destroy projectile //Instantiate effect string collidedObjectTag = collidedObject.tag; if (collidedObjectTag == shipTag) { //Damage enemy ship collidedObject.GetComponentInParent <Core_ShipController>().TakeDamage(shootDamage); //Destroy projectile DestroyProjectile(projectile); } else if (collidedObjectTag == environmentTag) { DestroyProjectile(projectile); } }
protected void Shoot() { if (canShoot && !shootOnCooldown) { //Spawn bullet at shipTurret position & rotation GameObject newBullet = Instantiate(Resources.Load("Bullet", typeof(GameObject)), turretOutputMarker.position, turretOutputMarker.rotation) as GameObject; Physics.IgnoreCollision(newBullet.GetComponent <Collider>(), GetComponentInChildren <Collider>()); newBullet.GetComponent <Rigidbody>().AddForce(newBullet.transform.forward * bulletLaunchForce, ForceMode.Impulse); Core_Projectile newBulletScript = newBullet.GetComponent <Core_Projectile>(); newBulletScript.SetProjectileType(Core_Projectile.EProjectileType.BULLET); newBulletScript.SetShipController(this); newBulletScript.SetProjectileColor(myShipColor); projectileList.Add(newBulletScript); //Set shoot on cooldown shootCooldownFrameTimer = shootCooldownFrames; shootOnCooldown = true; } }