コード例 #1
0
    protected override string Trigger(ShipController instance)
    {
        // Setup variables
        int        index      = 0;
        GameObject clone      = null;
        float      diffAngle  = 360f / maxNumBullets;
        Vector3    spawnAngle = transform.rotation.eulerAngles;

        BulletControllerHoming[] allGeneratedBullets = new BulletControllerHoming[maxNumBullets];
        int numEnemiesTargeted = 0;

        // Generate all bullets
        for (index = 0; index < maxNumBullets; ++index)
        {
            // Clone bullet
            clone = GlobalGameObject.Get <PoolingManager>().GetInstance(bullet.gameObject, transform.position, Quaternion.Euler(spawnAngle));
            allGeneratedBullets[index] = clone.GetComponent <BulletControllerHoming>();

            // Update angle
            spawnAngle.z += diffAngle;
            while (spawnAngle.z < 0)
            {
                spawnAngle.z += 360;
            }
        }

        // Search for enemies in range
        foreach (IDestructable candidate in IGameManager.Instance.AllDestructables())
        {
            if (candidate is IEnemy)
            {
                // Target this enemy
                allGeneratedBullets[numEnemiesTargeted].Target = (IEnemy)candidate;
                ++numEnemiesTargeted;

                // Make sure the number of targeted enemies doesn't exceed the number of bullets
                if (numEnemiesTargeted >= maxNumBullets)
                {
                    // If so, stop searching for enemies
                    break;
                }
            }
        }

        // Check if we have any bullets left that hasn't targeted an enemy
        if ((numEnemiesTargeted > 0) && (numEnemiesTargeted < maxNumBullets))
        {
            // Change the other bullet's target to the same enemies found earlier
            for (index = numEnemiesTargeted; index < maxNumBullets; ++index)
            {
                allGeneratedBullets[index].Target = allGeneratedBullets[(index % numEnemiesTargeted)].Target;
            }
        }

        return("Homing Bomb");
    }
コード例 #2
0
ファイル: IEnemy.cs プロジェクト: OmiyaGames/galactic-neon
 public void RemoveHomingBullet(BulletControllerHoming bullet)
 {
     if (bullet != null)
     {
         allHomingBullets.Remove(bullet);
         if ((allHomingBullets.Count <= 0) && (homingReticle != null))
         {
             homingReticle.SetActive(false);
             homingReticle = null;
         }
     }
 }
コード例 #3
0
    public void SetTarget(StageObject obj)
    {
        m_targetObject = obj;
        BulletControllerHoming bulletControllerHoming = controller as BulletControllerHoming;

        if (bulletControllerHoming != null)
        {
            bulletControllerHoming.SetTarget(obj);
        }
        BulletControllerBreakable bulletControllerBreakable = controller as BulletControllerBreakable;

        if (bulletControllerBreakable != null)
        {
            bulletControllerBreakable.SetTarget(obj);
        }
    }
コード例 #4
0
ファイル: IEnemy.cs プロジェクト: OmiyaGames/galactic-neon
    public void AddHomingBullet(BulletControllerHoming bullet)
    {
        if (bullet != null)
        {
            allHomingBullets.Add(bullet);
            if (bullet.reticle != null)
            {
                // Grab a reticle from the pool manager
                homingReticle = GlobalGameObject.Get <PoolingManager>().GetInstance(bullet.reticle);

                // Position the reticle
                Transform reticleTransform = homingReticle.transform;
                reticleTransform.position = transform.position;
                reticleTransform.rotation = Quaternion.identity;
                reticleTransform.parent   = transform;
            }
        }
    }