Пример #1
0
        private void SpawnLaser(Transform gunPos)
        {
            // Get a laser from the pool.
            GameObject laserGameObject = m_LaserObjectPool.GetGameObjectFromPool();

            // Set it's position and rotation based on the gun positon.
            laserGameObject.transform.position = gunPos.position;
            laserGameObject.transform.rotation = gunPos.rotation;

            // Find the FlyerLaser component of the laser instance.
            FlyerLaser flyerLaser = laserGameObject.GetComponent <FlyerLaser>();

            // Set it's object pool so it knows where to return to.
            flyerLaser.ObjectPool = m_LaserObjectPool;

            // Restart the laser.
            flyerLaser.Restart();

            // Play laser audio.
            m_LaserAudio.Play();
        }
Пример #2
0
        IEnumerator FireLaser(Transform gunPos)
        {
            isFireable = false;

            m_SonarChargeBar[0].fillAmount = 0;
            m_SonarChargeBar[1].fillAmount = 0;

            // Get a laser from the pool.
            GameObject laserGameObject = m_LaserObjectPool.GetGameObjectFromPool();

            // Set it's position and rotation based on the gun positon.
            laserGameObject.transform.position = gunPos.position;
            laserGameObject.transform.rotation = gunPos.rotation;

            if (m_Dolphin.isRayGreen)
            {
                laserGameObject.transform.GetChild(0).gameObject.SetActive(false);
                laserGameObject.transform.GetChild(1).gameObject.SetActive(true);
            }
            else
            {
                laserGameObject.transform.GetChild(0).gameObject.SetActive(true);
                laserGameObject.transform.GetChild(1).gameObject.SetActive(false);
            }



            // Find the FlyerLaser component of the laser instance.
            FlyerLaser flyerLaser = laserGameObject.GetComponent <FlyerLaser>();

            // Set it's object pool so it knows where to return to.
            flyerLaser.ObjectPool = m_LaserObjectPool;

            // Restart the laser.
            flyerLaser.Restart();

            // Play laser audio.
            m_LaserAudio.panStereo = Input.GetAxis("LS Horizontal");
            m_LaserAudio.Play();

            //Recharge shot before firing again.
            float startRotation = 0;
            float endRotation   = startRotation + 90.0f;
            float t             = 0.0f;

            while (t < m_LaserChargeTime)
            {
                t += Time.deltaTime;

                float x = Mathf.Lerp(startRotation, endRotation, t / m_LaserChargeTime) % 90.0f;


                m_SonarChargeBar[0].fillAmount = Mathf.Sin(x * Mathf.Deg2Rad);
                m_SonarChargeBar[1].fillAmount = Mathf.Sin(x * Mathf.Deg2Rad);

                yield return(null);
            }

            isFireable = true;

            m_SonarChargeBar[0].fillAmount = 1f;
            m_SonarChargeBar[1].fillAmount = 1f;
        }