Exemple #1
0
 private void DestroyProjectile(Core_Projectile projectile)
 {
     projectileList.Remove(projectile);
     if (projectile != null)
     {
         Destroy(projectile.gameObject);
     }
 }
Exemple #2
0
 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--;
             }
         }
     }
 }
Exemple #3
0
    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);
        }
    }
Exemple #4
0
 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;
     }
 }