Beispiel #1
0
    private void M_FireWeapon()
    {
        CannonShell newProjectile = Instantiate(m_projectilePrefab, m_cannonObj.transform.position, m_cannonObj.transform.rotation).GetComponent <CannonShell>();

        // Spread it some
        //float spreadx = Random.Range(-m_weaponSpread, m_weaponSpread);
        //float spready = Random.Range(-m_weaponSpread, m_weaponSpread);
        //newProjectile.transform.Rotate(spreadx, spready, 0, Space.Self);
        newProjectile.GetComponent <Rigidbody>().velocity = m_cannonObj.transform.forward.normalized * m_fireVelocity;
        // Add firing unit to the projectile so it doesnt hit itself
        newProjectile.M_Init();
        newProjectile.m_firingUnitObject = gameObject;
        newProjectile.M_FireAtTarget(m_fireVelocity, m_target);

        //firingUnit.M_AddRecoil(newProjectile.transform.forward * m_recoil);
        //m_readyToFire = false;
        //m_currentCooldown = m_maxCooldown;
    }
    public bool Fire()
    {
        if (!OnCooldown() && currentShotCount < maximumShotCount)
        {
            GameObject  projectile  = Instantiate(projectilePrefab, firePoint.position, Quaternion.LookRotation(firePoint.forward));
            CannonShell cannonShell = projectile.GetComponent <CannonShell>();
            cannonShell.OnDeath += CannonShell_OnDeath;

            Instantiate(fireEffect, firePoint.position, Quaternion.identity);

            currentShotCount++;

            lastFireTime = Time.time;
            return(true);
        }
        else
        {
            return(false);
        }
    }
Beispiel #3
0
 void OnProjectileDestroyed(CannonShell shell)
 {
     projectiles.Remove(shell);
     bulletsVariable.Value.Remove(shell.gameObject);
 }