Esempio n. 1
0
    private void HandleFiring()
    {
        // start cooldown for shots
        if (m_shotCoolDown > 0f)
        {
            m_shotCoolDown -= Time.deltaTime;
        }
        if (m_shotCoolDown <= 0f && Input.GetKey(KeyCode.Space))
        {
            //shot cooldown
            m_shotCoolDown = 1f / m_shotsPerSecond;

            // left bullet spawn - get a new bullet from the pooler
            GameObject newBulletLeft = m_playerBulletPooler.GetPlayerBullet();

            // set bullet position and rotation using ship position and offsets in bulletOriginLeft
            newBulletLeft.transform.position = transform.TransformPoint(m_bulletOriginLeft);
            newBulletLeft.transform.rotation = transform.rotation;
            newBulletLeft.GetComponent <Rigidbody2D>().velocity = newBulletLeft.transform.up * m_playerBulletSpeed;

            // right bullet spawn - get a new bullet from the pooler
            GameObject newBulletRight = m_playerBulletPooler.GetPlayerBullet();

            // set bullet position and rotation using ship position and offsets in bulletOriginRight
            newBulletRight.transform.position = transform.TransformPoint(m_bulletOriginRight);// transform.position + new Vector3(bulletOriginRight.x, bulletOriginRight.y);
            newBulletRight.transform.rotation = transform.rotation;
            newBulletRight.GetComponent <Rigidbody2D>().velocity = newBulletRight.transform.up * m_playerBulletSpeed;
        }
    }
Esempio n. 2
0
    private void HandleFiring()
    {
        // check for fire button press#
        if (m_shotCoolDown > 0f)
        {
            m_shotCoolDown -= Time.deltaTime;
        }
        if (m_shotCoolDown <= 0f && Input.GetKeyDown(KeyCode.Z))
        {
            // spawn new bullet
            GameObject bullet = m_playerBulletPooler.GetPlayerBullet();
            bullet.GetComponent <BulletScript>().Fire();
            bullet.transform.position = m_firePoints[m_fireIndex].transform.position;
            bullet.transform.rotation = m_firePoints[m_fireIndex].transform.rotation;
            bullet.GetComponent <Rigidbody2D>().velocity = bullet.transform.up * m_shotSpeed;

            // set muzzle flash to fired cannon
            m_muzzleFlash.SetActive(true);
            m_muzzleFlash.transform.position = m_firePoints[m_fireIndex].transform.position;
            m_muzzleFlash.transform.rotation = m_firePoints[m_fireIndex].transform.rotation;

            // cycle fire points
            m_fireIndex++;
            if (m_fireIndex >= m_firePoints.Count)
            {
                m_fireIndex = 0;
            }

            // set cooldown
            m_shotCoolDown = 1f / m_shotsPerSecond;
        }
        else
        {
            // hide muzzle flash
            m_muzzleFlash.SetActive(false);
        }
    }