GetBullet() public method

public GetBullet ( ) : GameObject
return GameObject
Exemplo n.º 1
0
    protected override void Fire()
    {
        float angleStep = 360 / Amount;
        float angle     = 0;

        float   directionX;
        float   directionY;
        Vector2 direction;

        for (int i = 0; i < Amount + 1; i++)
        {
            directionX = Mathf.Cos((angle * Mathf.PI) / 180f);
            directionY = Mathf.Sin((angle * Mathf.PI) / 180f);
            direction  = new Vector2(directionX, directionY);
            direction  = direction.normalized;

            Bullet bullet = BulletPool.GetBullet();
            bullet.transform.position    = transform.position + (Vector3)direction * 2f;
            bullet.transform.eulerAngles = new Vector3(0, 0, angle - 90);
            bullet.gameObject.SetActive(true);
            bullet.SetData(direction, 3, 0.1f, 10f, 1, 0);
            angle += angleStep;
        }

        _count++;
        if (_count == 3)
        {
            CancelInvoke("Fire");
        }
    }
Exemplo n.º 2
0
    private void Shoot()
    {
        // Get reusable bullet object from Bullet Pool
        GameObject bullet = bulletPool.GetBullet();

        //Set Bullet attributes
        bullet.transform.position = cachedFirePointTransform.position;
        bullet.transform.rotation = cachedFirePointTransform.rotation;
        Bullet b = bullet.GetComponent <Bullet>();

        b.SetDirection(cachedFirePointTransform.up);
        b.SetSpeed(bulletSpeed);
        b.SetDamage(1);
        b.SetHostility(false);

        bulletPool.PlaySound(transform.position);
        animator.SetTrigger("thePillFire");

        //Activate bullet object (must happen last)
        bullet.SetActive(true);

        //Instantiate(bulletPrefab, cachedFirePointTransform.position, cachedFirePointTransform.rotation);
        //Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
        //rb.AddForce(cachedFirePointTransform.up * bulletSpeed, ForceMode2D.Impulse);
    }
Exemplo n.º 3
0
    /// <summary>
    /// 射击方法
    /// </summary>
    private void Shooting()
    {
        if (Camera.main != null)
        {
            if (bulletCount > 0 && !isChangeAmmuniting)
            {
                //todo:实例化显示枪焰
                GameObject flame = Instantiate(gunFlame);
                flame.transform.parent        = muzzle.transform;
                flame.transform.position      = muzzle.transform.position;
                flame.transform.localRotation = Quaternion.Euler(new Vector3(180, 0, 0));
                flame.transform.localScale    = new Vector3(0.4f, 0.4f, 0.4f);

                bulletCount--;

                // 以摄像机所在位置为起点,创建一条向里侧发射的射线
                Ray        ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
                RaycastHit hit;

                GameObject go = bulletPool.GetBullet();
                go.transform.position = muzzle.transform.position;
                go.transform.rotation = muzzle.transform.rotation;
                Bullet bullet = go.GetComponent <Bullet>();
                bullet.bulletPool   = bulletPool;
                bullet.moveSpeed    = moveSpeed;
                bullet.maxDistance  = maxDistance;
                bullet.startVector3 = muzzle.transform.position;
                //todo:  bullet.DazhongClip = GameObjectManager.Instance.DazhongClip;
                //todo:  bullet.hit = GameObjectManager.Instance.Hit2;
                bullet.bulletPower = bulletPower;

                if (Physics.Raycast(ray, out hit, 200f, _layerMask))
                {
                    if (hit.collider.tag == "Enemy")
                    {
                        bullet.HitGameObject = hit.collider.gameObject;
                        bullet.IsXueWuTexiao = true;
                    }
                    bullet.endVector3 = hit.point;
                }
                //todo:  AudioPools.Instance.GetAudioSource(GameObjectManager.Instance.A, GameObjectManager.Instance.MainCamera.transform.position, 0.4f);
                bulletCount_Text.text = bulletCount + "/" + AllBulletCount;


                //if (Physics.Raycast(ray, out hit /*, Mathf.Infinity*/))
                //{
                //    // 如果射线与平面碰撞,打印碰撞物体信息
                //    Debug.Log("碰撞对象: " + hit.collider.name);
                //    //在场景视图中绘制射线
                //    Debug.DrawLine(ray.origin, hit.point, Color.red);
                //    Destroy(hit.collider.gameObject);
                //    //Shooting01(hit.point, hit.collider.gameObject);
                //}
            }
        }
        else
        {
            //todo:  AudioPools.Instance.GetAudioSource(GameObjectManager.Instance.A, GameObjectManager.Instance.MainCamera.transform.position, 0.4f);
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (property.isPlaying == false)
        {
            return;
        }

        if (accumulatedTime < shootinterval)
        {
            accumulatedTime += Time.deltaTime;
            return;
        }
        else
        {
            accumulatedTime = 0.0f;
        }

        GameObject bullet = bulletPool.GetBullet(0);

        bullet.transform.position = gunBase[dirIdx].transform.position;
        Vector3 dir = bullet.transform.position - transform.position;

        bullet.GetComponent <BulletProperty>().direction.x = dir.x;

        bullet.GetComponent <BulletProperty>().direction.y = dir.y;

        ++dirIdx;
        dirIdx %= 8;
    }
Exemplo n.º 5
0
    private GameObject SpawnBullet()
    {
        GameObject _bt = null;

        switch (currWeapon.bulletType)
        {
        case 0:

            _bt = stonebulletPool.GetBullet();
            break;

        case 1:

            _bt = magicbulletPool.GetBullet();
            break;

        case 2:

            _bt = regularbulletPool.GetBullet();
            break;

        default:

            Debug.LogWarning("ERROR AT POOLING BULLET IN PLAYERSHOOTING!");
            break;
        }

        _bt.transform.position = gunPoint.position;
        _bt.SetActive(true);

        return(_bt);
    }
Exemplo n.º 6
0
        private IEnumerator Fire()
        {
            realFireSpeed = 100f / fireSpeed;
            realAccuracy  = (maxAccuracy - Mathf.Clamp(accuracy, minAccuracy, maxAccuracy)) / maxAccuracy;

            isBulletFire = true;
            var bullet   = bulletPool.GetBullet();
            var enemyPos = nearestEnemy.GetComponent <Transform>().position;

            var spawnPointPosWorld = transform.Find("Gun/BulletSpawnPoint").transform.position;

            var distanceY = enemyPos.y - spawnPointPosWorld.y;
            var distanceX = enemyPos.x - spawnPointPosWorld.x;

            distanceY = Random.Range(distanceY * (1f - realAccuracy), distanceY * (1f + realAccuracy));

            var angle = Mathf.Atan(distanceY / distanceX);

            angle = Mathf.Rad2Deg * angle;

            var rotation = Quaternion.AngleAxis(angle, Vector3.forward);

            Vector3 bulletForceVector = new Vector2(distanceX, distanceY);

            bullet.GetComponent <Transform>().position = spawnPointPosWorld;
            bullet.GetComponent <Transform>().rotation = rotation;
            bullet.GetComponent <Bullet>().speed       = bulletSpeed;
            bullet.GetComponent <Bullet>().Fire(bulletForceVector);
            mainAudioSource.PlayOneShot(shootSound);
            yield return(new WaitForSeconds(realFireSpeed));

            isBulletFire = false;
        }
Exemplo n.º 7
0
    protected override void Fire()
    {
        float angleStep = 360 / Amount;
        float angle     = angleStep * _count;

        _count = (_count + 1) % Amount;

        float   directionX;
        float   directionY;
        Vector2 direction;

        if (_count % 10 == 0)
        {
            angle += angleStep;
            return;
        }

        directionX = Mathf.Cos((angle * Mathf.PI) / 180f);
        directionY = Mathf.Sin((angle * Mathf.PI) / 180f);
        direction  = new Vector2(directionX, directionY);
        direction  = direction.normalized;

        Bullet bullet = BulletPool.GetBullet();

        bullet.transform.position    = transform.position + (Vector3)direction * 2f;
        bullet.transform.eulerAngles = new Vector3(0, 0, angle + 90);
        bullet.gameObject.SetActive(true);
        bullet.SetData(direction, 2, 3f, 3f, 0, 0);
    }
Exemplo n.º 8
0
 public void FireFirst()
 {
     if (Time.time > lastFiredTime)
     {
         lastFiredTime = Time.time + delayAmount;
         bulletPool.GetBullet(bulletFireTransform);
     }
 }
Exemplo n.º 9
0
    public void Fire()
    {
        GameObject _newBullet = _manager.GetBullet();

        _newBullet.GetComponent <Bullet>().moveDir = transform.up;
        _newBullet.transform.position = top.transform.position;
        _newBullet.transform.rotation = transform.rotation;
    }
Exemplo n.º 10
0
    public void SpawnHoming()
    {
        for (int i = 0; i < data.amount; i++)
        {
            Bullet b = pool.GetBullet(data.type);
            b.Refresh();

            Vector2 angle = -((Vector2)this.transform.position - (Vector2)PlayerMovement.me.position).normalized;
            //angle = angle + (UnityEngine.Random.insideUnitCircle.normalized * 0.4f);
            //angle = angle.normalized;


            b.Activate(this.transform.position, angle, data.delay);
        }

        inUse = false;
    }
Exemplo n.º 11
0
    public void CastBullet()
    {
        //Get bullet from pool, reset, set velocity and enable
        Bullet bullet = bulletPool.GetBullet();

        bullet.transform.position = casterTransform.position;
        bullet.gameObject.SetActive(true);
        bullet.Cast(target.GetTarget() - casterTransform.position, speed);
    }
Exemplo n.º 12
0
    private void Shoot()
    {
        GameObject bullet = _BulletPool.GetBullet();

        if (bullet != null)
        {
            bullet.SetActive(true);
            bullet.transform.position = _Spawn.transform.position;
            bullet.GetComponent <Bullet>().SetBulletDirection(_Direction);
        }
    }
Exemplo n.º 13
0
    private void ShootQuadsinus()
    {
        float _bulletAmount = 50;
        float _angleStep    = 360 / _bulletAmount;
        float _angle        = transform.rotation.eulerAngles.z;
        float _offset       = (360 / 2) - (_angleStep / 2);

        for (int i = 0; i < _bulletAmount; i++)
        {
            float _currAngle = _angleStep * i;

            Quaternion _rot = Quaternion.Euler(new Vector3(0, 0, _angle + _currAngle - _offset));

            GameObject _b = bulletPool.GetBullet();

            _b.transform.rotation = _rot;
            _b.transform.position = gameObject.transform.position;
            _b.SetActive(true);
        }
    }
Exemplo n.º 14
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         //GameObject go = GameObject.Instantiate(bulletPrefab,transform.position,transform.rotation);
         GameObject go = bulletPool.GetBullet();
         go.transform.position = transform.position;
         go.GetComponent <Rigidbody>().velocity = transform.forward * 50;
         //Destroy(go, 3);
         StartCoroutine(DestroyBullet(go));
     }
 }
Exemplo n.º 15
0
    // Update is called once per frame
    void Update()
    {
        countDown -= Time.deltaTime;
        if (countDown <= 0.0f)
        {
            currentBullet = bulletPool.GetBullet();
            currentBullet.transform.position = new Vector3(this.transform.position.x, this.transform.position.y - 0.7f, this.transform.position.z);
            currentBullet.SetActive(true);
            currentBullet.GetComponent <Rigidbody2D>().AddForce(new Vector2(0, -bulletSpeed));

            countDown = fireRate;
        }
    }
Exemplo n.º 16
0
        private void Shoot(float deltaTime)
        {
            _timer += deltaTime;
            if (_timer >= _shootCooldown)
            {
                _timer = 0.0f;
                var bullet = _bulletPool.GetBullet(BulletTypes.Laser);

                ManagePool(bullet);

                bullet.OnBulletHit += OnBulletHit;
                bullet.Shoot();
            }
        }
Exemplo n.º 17
0
    // Fires a volley to a collision layer.
    public bool Fire(int layer, Vector3 baseVelocity)
    {
        // If we are ready to fire
        if (coolDown <= 0 && HasAmmo())
        {
            // Get position and direction from the muzzle
            Vector3 pos      = Muzzle.position;
            Vector3 velocity = Muzzle.right * BulletSpeed;

            // Fire the whole volley
            for (int i = 0; i < Volley && HasAmmo(); i++)
            {
                GameObject fired = null;
                if (pool != null)
                {
                    fired = pool.GetBullet();
                }
                else
                {
                    fired = Instantiate(Bullet);
                }
                if (fired == null)
                {
                    return(false);
                }
                fired.transform.position = pos;
                float          angle    = Random.Range(-Spread, Spread);
                BulletMovement movement = fired.GetComponent <BulletMovement>();
                if (movement != null)
                {
                    movement.SetUp((UseBaseVelocity ? baseVelocity : Vector3.zero) + (Quaternion.Euler(0, 0, angle) * velocity), Damage, Range / BulletSpeed);
                }
                fired.layer = layer;
                currentAmmo--;
            }

            // Reset cooldown
            if (coolDown != -1)
            {
                coolDown = RateOfFire;
            }
            return(true);
        }
        else
        {
            return(false);
        }
    }
Exemplo n.º 18
0
    protected virtual IEnumerator Fire()
    {
        yield return(new WaitForSeconds(startFireTimer));

        while (isFiring)
        {
            bullet = bulletPool.GetBullet();
            bullet.transform.position = transform.position;
            bullet.transform.rotation = transform.rotation;
            bullet.gameObject.SetActive(true);

            PlayAudio();

            yield return(new WaitForSeconds(fireRate));
        }
    }
Exemplo n.º 19
0
    private void Update()
    {
        if (m_sphere == null)
        {
            return;
        }
        m_fireTime -= Time.deltaTime;

        if (m_fireTime < 0)
        {
            var bullet = m_bulletPool.GetBullet(transform);
            bullet.transform.position = transform.position;
            transform.LookAt(m_sphere.transform);
            bullet.GetComponent <Rigidbody>().velocity = transform.forward * m_bulletSpeed;
            m_fireTime = 5f;
        }
    }
Exemplo n.º 20
0
    protected void Shoot(Transform origin, float moveSpeed, float ttl)
    {
        // Get reusable bullet object from Bullet Pool
        GameObject bullet = bulletPool.GetBullet();

        //Set Bullet attributes
        bullet.transform.position = origin.position;
        bullet.transform.rotation = origin.rotation;
        Bullet b = bullet.GetComponent <Bullet>();

        b.SetDirection(origin.up);
        b.SetSpeed(moveSpeed);
        b.SetHostility(true);
        b.SetTimeToLive(ttl);

        //Activate bullet object (must happen last)
        bullet.SetActive(true);
    }
Exemplo n.º 21
0
 // Update is called once per frame
 void Update()
 {
     childRotater.transform.Rotate(Vector3.forward * Time.deltaTime * 45.0f);
     if (shootTime <= 0.0f)
     {
         for (int i = 0; i < spawnBulletPositions.Length; i++)
         {
             bulletToShoot = gameBullets.GetBullet();
             bulletToShoot.transform.position = spawnBulletPositions[i].transform.position;
             bulletToShoot.transform.rotation = spawnBulletPositions[i].transform.rotation;
             bulletToShoot.ActivateBullet();
         }
         shootTime = originalShootTime;
     }
     else
     {
         shootTime -= Time.deltaTime;
     }
 }
Exemplo n.º 22
0
    //
    public void Shoot(float dt)
    {
        //Debug.Log(shootPoint);
        GameObject proyectileToUse = bulletPool.GetBullet(proyectilePrefab);

        if (!proyectileToUse)
        {
            return;
        }
        // TODO: Incluir shootCalculation
        //GameObject newProyectile = GeneralFunctions.ShootProjectile(proyectilePrefab, shootPoint.position,
        //    shootPoint.rotation, shootPoint.forward, muzzleSpeed, dt, ShootCalculation.MuzzleSpeed);
        GeneralFunctions.ShootProjectileFromPool(proyectileToUse, shootPoint.position,
                                                 shootPoint.rotation, shootPoint.forward, muzzleSpeed, dt, ShootCalculation.MuzzleSpeed);
        //
        if (shootParticlesPrefab != null)
        {
            Instantiate(shootParticlesPrefab, shootPoint.position, Quaternion.identity);
        }
        //
        Missile missile = proyectileToUse.GetComponent <Missile>();

        if (missile != null)
        {
            missile.AssignObjective(player.transform);
            Debug.Log(player.transform);
        }


        //
        //if (!enemyManager.IsFiringClipActive(shootingClip))
        //{
        //    enemyManager.AddClip(shootingClip);
        GeneralFunctions.PlaySoundEffectWithoutOverlaping(audioSource, shootingClip);
        //}

        // TODO: Revisar por qué sale tan gore
        Rigidbody proyectileRb = proyectileToUse.GetComponent <Rigidbody>();
        float     lauchForce   = proyectileRb.velocity.magnitude * proyectileRb.mass;

        bodyRb.AddForce(-transform.forward * lauchForce);
    }
Exemplo n.º 23
0
    public GameObject SpawnBullet(Vector3 pos, Quaternion rot, List <GameObject> bulletTypeList)
    {
        int index = 0;

        if (bulletTypeList == bulletPool.basicBullets)
        {
            index = 0;
        }
        else
        {
            index = 1;
        }

        GameObject go = bulletPool.GetBullet(bulletTypeList, index);

        go.transform.position = pos;
        go.transform.rotation = rot;
        go.SetActive(true);
        return(go);
    }
Exemplo n.º 24
0
    void Update()
    {
        if (player.state != Player.PlayerStates.idle && player.state != Player.PlayerStates.moving)
        {
            return;
        }

        if (Input.GetKey(KeyCode.Mouse0))
        {
            if (canShoot)
            {
                Bullet newBullet = bulletPool.GetBullet();
                newBullet.transform.position = gun.transform.position;
                newBullet.transform.rotation = gun.transform.rotation;
                newBullet.gameObject.SetActive(true);
                newBullet.SetAsActive();
                canShoot = false;
                StartCoroutine(FireDelay());
            }
        }
    }
Exemplo n.º 25
0
    void Shoot()
    {
        gunshotSfx.Play();
        if (projectile)
        {
            Bullet bullet = bulletPool.GetBullet();
            if (bullet == null)
            {
                return;                // should never happen after we implement ammo
            }
            List <int> damages         = CalculateDamage();
            int        normalDamage    = damages[0];
            int        weakpointDamage = damages[1];
            bullet.SetWeakpointDamage(weakpointDamage);

            RaycastHit hit;
            if (Physics.Raycast(thirdPersonCamera.transform.position, thirdPersonCamera.transform.forward, out hit, bulletRange))
            {
                bullet.Initialize(bulletSpawnpoint.position, normalDamage, (hit.point - bulletSpawnpoint.position));
            }
            else // if there is no target, just shoot the bullet to maximum range in the direction of the centre of screen
            {
                // get position of bulletrange distance away from camera
                Vector3 farthestPoint = thirdPersonCamera.transform.position + thirdPersonCamera.transform.forward * bulletRange;
                bullet.Initialize(bulletSpawnpoint.position, normalDamage, (farthestPoint - bulletSpawnpoint.position));
            }
        }
        else
        {
            RaycastHit hit;
            if (Physics.Raycast(thirdPersonCamera.transform.position, thirdPersonCamera.transform.forward, out hit, bulletRange))
            {
                Instantiate(impactParticles, hit.point, Quaternion.LookRotation(hit.normal));
                if (hit.transform.GetComponent <EnemyHealth>() != null)
                {
                    DamageEnemy(hit);
                }
            }
        }
    }
Exemplo n.º 26
0
    private void Update()
    {
        var diffPos = transform.position - m_sphere.transform.position;

        if (diffPos.magnitude > 0.01f)
        {
            transform.rotation = Quaternion.LookRotation(-diffPos);
        }
        transform.position = m_sphere.transform.position;

        if (m_isFire)
        {
            var bullet = m_bulletPool.GetBullet(transform);
            if (bullet == null)
            {
                return;
            }
            bullet.transform.position = transform.position + transform.forward;
            bullet.GetComponent <Rigidbody>().velocity = transform.forward * m_bulletSpeed;
            m_isFire = false;
        }
    }
Exemplo n.º 27
0
    /// <summary>
    ///
    /// </summary>
    void CharguedProyectileAttack(GameObject proyectilePrefab, Transform muzzlePoint, float dt)
    {
        //
        //GameObject nextProyectile = GeneralFunctions.ShootProjectile(proyectilePrefab, muzzlePoint.position, muzzlePoint.rotation,
        //    muzzlePoint.forward, forceToApply, dt, ShootCalculation.Force);
        GameObject nextProyectile = bulletPool.GetBullet(elipticProyectilePrefab);

        // Establecemos la masa
        // TODO: Cambiarlo en la instancia
        Rigidbody nextProyectileRb = nextProyectile.GetComponent <Rigidbody>();

        nextProyectileRb.mass = gameManager.playerAttributes.massPerSecond * chargedAmount / 1000000;
        // Y la fuerza a aplicar
        float forceToApply = gameManager.playerAttributes.forcePerSecond.CurrentValue * chargedAmount;

        //
        //Debug.Log("Proyectile mass: " + proyectileRb.mass + ", force to apply: " + forceToApply);

        //
        GeneralFunctions.ShootProjectileFromPool(nextProyectile, muzzlePoint.position, muzzlePoint.rotation,
                                                 muzzlePoint.forward, forceToApply, dt, ShootCalculation.Force);
        // TODO: Revisar diametro, densidad, etc
        Bullet bulletComponent = nextProyectile.GetComponent <Bullet>();
        //
        float volume = proyectileRb.mass / gameManager.playerAttributes.currentDensity;
        // =(volume*3/(4*PI()*ratioAB))^(1/3) * 2
        float ratioAB        = 2;
        float elipseDiameter = Mathf.Pow((volume * 3 / (4 * Mathf.PI * ratioAB)), 1 / 3) * 2;

        bulletComponent.diameter = elipseDiameter;
        bulletComponent.length   = elipseDiameter * ratioAB;
        //
        rb.AddForce(-chargedProyectilePoint.forward * forceToApply, ForceMode.Impulse);
        ChangeDampingType(DampingType.ThreeDimensional);
        //
        GameObject muzzleParticles = Instantiate(shootParticlePrefab, muzzlePoint.position, muzzlePoint.rotation);

        muzzleParticles.transform.localScale = Vector3.one * (1 + (chargedAmount * 10));
    }
Exemplo n.º 28
0
    protected void CreateBullet()
    {
        Bullet bullet;

        if (pool == null)
        {
            //print("null");

            var obj = Instantiate(gunPrefab, muzzleTransform.position, muzzleTransform.rotation);
            bullet = obj.GetComponent <Bullet>();
        }
        else
        {
            bullet      = pool.GetBullet();
            bullet.pool = pool;
            bullet.gameObject.transform.position = muzzleTransform.position;
            bullet.gameObject.transform.rotation = muzzleTransform.rotation;
        }
        bullet.range    = gunRange;
        bullet.damage   = damage;
        bullet.Attacker = gameObject;
        bullet.Initialize();
    }
Exemplo n.º 29
0
    protected override void Fire()
    {
        float angleStep = (EndAngle - StartAngle) / Amount;
        float angle     = StartAngle;

        float   directionX;
        float   directionY;
        Vector2 direction;

        for (int i = 0; i < Amount + 1; i++)
        {
            directionX = Mathf.Cos((angle * Mathf.PI) / 180f);
            directionY = Mathf.Sin((angle * Mathf.PI) / 180f);
            direction  = new Vector2(directionX, directionY);
            direction  = direction.normalized;

            Bullet bullet = BulletPool.GetBullet();
            bullet.transform.position = transform.position;
            bullet.transform.rotation = transform.rotation;
            bullet.gameObject.SetActive(true);
            bullet.SetData(direction, 3, 1, 1, 0, 0);
            angle += angleStep;
        }
    }
Exemplo n.º 30
0
    void LaunchBullet()
    {
        Bullet bullet = bulletPool.GetBullet();

        bullet.Initialize(bulletSpawnpoint.position, damage, barrel.forward);
    }