Exemple #1
0
    public void Shoot(float projectileSize = 5, float soundVolume = 0.1f)
    {
        if (Time.time > timeToFire)
        {
            if (Firerate > 0)
            {
                timeToFire = Time.time + 1 / Firerate;
            }

            int randomAmmo = rand.Next(0, Ammunition.Length);

            GameObject ammu = Instantiate(Ammunition[randomAmmo], firePoint.position, firePoint.rotation);
            ammu.transform.localScale = new Vector3(projectileSize, projectileSize, 1);
            ammu.transform.Rotate(new Vector3(0, 0, -90));

            ammu.GetComponent <AudioSource>().volume = soundVolume;

            ProjectileLogic ammuLogic = ammu.GetComponent <ProjectileLogic>();
            ammuLogic.AvoidCollisionByGameObject(gameObject);

            float currentSpread = UnityEngine.Random.Range(-Spread, Spread);

            Vector3 travelDirection       = (firePoint.position - transform.position);
            Vector3 travelDirectionSpread =
                new Vector3(travelDirection.x + currentSpread, travelDirection.y + currentSpread);

            ammuLogic.Initiate(travelDirectionSpread, Damage, Speed);
        }
    }
Exemple #2
0
    // Use this for initialization
    void Awake()
    {
        firePoint = gameObject.transform.Find("Firepoint");
        rand      = new System.Random();

        // to ensure ammunition flies faster than players
        PlayerSpaceshipController shipController = GetComponent <PlayerSpaceshipController>();

        if (shipController != null)
        {
            //Speed += shipController.AccelerationForce;
            playerId = shipController.PlayerId;
        }

        if (firePoint == null)
        {
            Debug.LogError("Firepoint was null. Is child missing or named wrong?");
        }


        ProjectileLogic projectileLogic = null;

        foreach (GameObject ammuType in Ammunition)
        {
            projectileLogic = ammuType.GetComponent <ProjectileLogic>();

            if (projectileLogic == null)
            {
                Debug.LogError("Ammunition \"" + ammuType.name + "\" does not have ProjectileLogic component.");
            }
        }
    }
        public override bool PreAI(Projectile projectile)
        {
            if (projectile.aiStyle == 7 && !projectile.npcProj)
            {
                ProjectileLogic.UpdateForGrappleProjectileForPlayer(Main.player[projectile.owner], projectile);
            }

            return(base.PreAI(projectile));
        }
Exemple #4
0
    private void FireProjectile()
    {
        ProjectileLogic projectile = ProjectileManager.Instance.GetProjectile();

        if (projectile != null)
        {
            projectile.SetupProjectileData(playerProjectile);
            projectile.transform.position = projectileSource.position;
            projectile.transform.rotation = projectileSource.rotation;
            projectile.gameObject.SetActive(true);
        }
        else
        {
            Debug.Log("ERROR: Available Projectile Not Found");
        }
    }
    private void FireProjectile(Weapon source, float firingAngle)
    {
        if (source != null)
        {
            ProjectileLogic projectile = ProjectileManager.Instance.GetProjectile();

            if (projectile != null)
            {
                projectile.SetupProjectileData(projectileToFire);
                projectile.transform.position = source.attackSource.position;
                projectile.transform.rotation = source.attackSource.rotation * Quaternion.Euler(0, 0, firingAngle);
                projectile.gameObject.SetActive(true);
            }
            else
            {
                Debug.Log("ERROR: Available Projectile Not Found");
            }
        }
    }
    public ProjectileLogic GetProjectile()
    {
        for (int i = 0; i < projectilePool.Count; i++)
        {
            if (!projectilePool[listIndex].activeInHierarchy)
            {
                ProjectileLogic projectile = projectilePool[listIndex].GetComponent <ProjectileLogic>();

                return(projectile);
            }

            listIndex++;
            if (listIndex >= projectilePool.Count)
            {
                listIndex = 0;
            }
        }

        Debug.Log("inactive projectile not found");
        return(null);
    }
Exemple #7
0
    private void Shoot(int primaryOrSecondary)
    {
        if (m_primaryProjectile == null || m_secondaryProjectile == null)
        {
            return;
        }

        if (primaryOrSecondary == 0)
        {
            m_projectile      = Instantiate(m_primaryProjectile, m_projectileBarrel.position, m_projectileBarrel.rotation);
            m_projectileLogic = m_projectile.GetComponent <ProjectileLogic>();
            m_projectileLogic.SetElementLevel(m_playerStats.m_primaryElement.elementLevel, m_playerStats.m_attackDamage);
        }
        else if (primaryOrSecondary == 1)
        {
            m_projectile      = Instantiate(m_secondaryProjectile, m_projectileBarrel.position, m_projectileBarrel.rotation);
            m_projectileLogic = m_projectile.GetComponent <ProjectileLogic>();
            m_projectileLogic.SetElementLevel(m_playerStats.m_secondaryElement.elementLevel, m_playerStats.m_attackDamage);
        }

        m_animator.SetTrigger("Projectile Right Attack 01");
        m_projectileLogic.FireProjectile(GetPlayerDirection());
    }
 public override void GrapplePullSpeed(Projectile projectile, Player player, ref float speed)
 {
     ProjectileLogic.UpdateGrapplePullSpeedForPlayer(player, projectile, ref speed);
 }
Exemple #9
0
 void DestroyLogicAndDontFly()
 {
     Destroy(projectile);
     projectile = null;
 }