Esempio n. 1
0
    public void PlayInPosition(string gClip, Vector3 pos, float MaxDistance = 47f)
    {
        GameObject currentInstance = null;

        for (int i = 0; i < m_listInstances.Count; i++)
        {
            if (!m_listInstances[i].GetComponent <AudioSource>().isPlaying)
            {
                currentInstance = m_listInstances[i];
                break;
            }
        }

        if (currentInstance == null)
        {
            currentInstance = (GameObject)Instantiate(m_res.GetObject(m_sInstancePrefab));
            currentInstance.transform.parent = m_tInstancesContainer;
            m_listInstances.Add(currentInstance);
        }

        currentInstance.transform.position = pos;
        currentInstance.GetComponent <AudioSource>().spatialBlend = 1f;
        currentInstance.GetComponent <AudioSource>().maxDistance  = MaxDistance;
        currentInstance.GetComponent <AudioSource>().pitch        = 1f;
        currentInstance.GetComponent <AudioSource>().clip         = m_res.GetClip(gClip);
        currentInstance.GetComponent <AudioSource>().Play();

        if (m_dicVolumeGroup.ContainsKey(currentInstance.tag))
        {
            currentInstance.GetComponent <AudioSource>().volume = m_dicVolumeGroup[currentInstance.tag];
        }
        else
        {
        }
    }