Ejemplo n.º 1
0
        private IEnumerator Fire(Transform target)
        {
            // Play the sound of the gun firing.
            m_GunAudio.Play();

            // Set the length of the line renderer to the default.
            float lineLength = m_DefaultLineLength;

            // If there is a target, the line renderer's length is instead the distance from the gun to the target.
            if (target)
            {
                lineLength = Vector3.Distance(m_GunEnd.position, target.position);
            }

            // Chose an index for a random flare mesh.
            int randomFlareIndex = Random.Range(0, m_FlareMeshes.Length);

            // Store the rotation of that random flare and set it randomly rotate around the z axis.
            Vector3 randomEulerRotation = m_FlareMeshes[randomFlareIndex].transform.eulerAngles;

            randomEulerRotation.z = Random.Range(0f, 360f);

            // Set the random rotation that has been stored back to the flare and turn it on.
            m_FlareMeshes[randomFlareIndex].transform.eulerAngles = randomEulerRotation;
            m_FlareMeshes[randomFlareIndex].SetActive(true);

            // Play the particle system for the gun.
            m_FlareParticles.Play();

            // Turn the line renderer on.
            m_GunFlare.enabled = true;

            SessionData.AddShoots();
            // Whilst the line renderer is on move it with the gun.
            yield return(StartCoroutine(MoveLineRenderer(lineLength)));

            // Turn the line renderer off again.
            m_GunFlare.enabled = false;

            // Turn the random flare mesh off.
            m_FlareMeshes[randomFlareIndex].SetActive(false);
        }