Exemplo n.º 1
0
        /// <summary>
        /// Fires a single projectile.
        /// </summary>
        /// <param name="data">Data about projectile.</param>
        virtual protected IEnumerator FireSingleProjectile(MultiProjectileAttackData attack, MultiProjectileData data)
        {
            int currentAttackTmp = currentAttack;

            yield return(new WaitForSeconds(data.delay));

            GameObject go         = (GameObject)GameObject.Instantiate(data.projectilePrefab);
            Projectile projectile = go.GetComponent <Projectile>();

            if (projectileAimer != null)
            {
                go.transform.position = character.transform.position + (Vector3)projectileAimer.GetAimOffset(character) + new Vector3(data.positionOffset.x * character.LastFacedDirection, data.positionOffset.y, 0);
            }
            else
            {
                go.transform.position = character.transform.position + new Vector3(data.positionOffset.x * character.LastFacedDirection, data.positionOffset.y, 0);
            }

            if (projectile != null)
            {
                // Fire projectile if the projectile is of type projectile
                Vector2 direction = new Vector2(character.LastFacedDirection != 0 ? character.LastFacedDirection : 1, 0);
                // Use aimer to get direction fo fire if the aimer is configured
                if (projectileAimer != null)
                {
                    direction = projectileAimer.GetAimDirection(character);
                }
                direction = Quaternion.Euler(0, 0, data.angleOffset * character.LastFacedDirection) * direction;

                if (data.flipX)
                {
                    direction.x *= -1;
                }
                if (data.flipY)
                {
                    direction.y *= -1;
                }
                projectile.Fire(attack.damageAmount, attack.damageType, direction, character);
            }

            // If the projectile is found and the go is still alive call finish
            if (projectile != null && go != null)
            {
                projectile.Finish();
            }
            ConsumeAmmo(attacks [currentAttackTmp]);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Instatiates a projectile.
        /// </summary>
        /// <param name="attackIndex">Index of the projectile to instantiate.</param>
        virtual public void InstantiateProjectile(int attackIndex)
        {
            // If attack index == -1 then we should use the deferred attack.
            if (attackIndex == -1)
            {
                attackIndex = deferredAttackIndex;
            }
            // Instantiate prefab
            GameObject go         = (GameObject)GameObject.Instantiate(attacks[attackIndex].projectilePrefab);
            Projectile projectile = go.GetComponent <Projectile>();

            if (projectileAimer != null)
            {
                go.transform.position = character.transform.position + (Vector3)projectileAimer.GetAimOffset(character);
            }
            else
            {
                go.transform.position = character.transform.position;
            }

            if (projectile != null)
            {
                // Fire projectile if the projectile is of type projectile
                Vector2 direction = new Vector2(character.LastFacedDirection != 0 ? character.LastFacedDirection : 1, 0);
                // Use aimer to get direction fo fire if the aimer is configured
                if (projectileAimer != null)
                {
                    direction = projectileAimer.GetAimDirection(character);
                }
                projectile.Fire(attacks[attackIndex].damageAmount, attacks[attackIndex].damageType, direction, character);
            }
            // If the projectile is found and the go is still alive call finish
            if (projectile != null && go != null)
            {
                projectile.Finish();
            }
        }