Esempio n. 1
0
    ///////////////////////////////////////////
    /// Init()
    /// Configures the actual audio source and
    /// plays the sound.
    ///////////////////////////////////////////
    public void Init(string strResource, Transform tf, Hashtable i_hashOptional)
    {
        // load the clip
        AudioClip clip = Resources.Load(strResource) as AudioClip;

        if (clip == null)
        {
            Debug.LogError("No such sound clip for resource " + strResource);
            Destroy(gameObject);
            return;
        }

        // create the audio source
        audioSource      = gameObject.AddComponent <AudioSource>();
        audioSource.clip = clip;

        // set the default volume (may be overriden)
        float fDefaultVolume = Constants_OLD.GetConstant <float>("DefaultVolume");

        audioSource.volume = fDefaultVolume;

        ID_Audio dataAudio = IDL_Audio.GetData(strResource);

        if (dataAudio != null)
        {
            audioSource.volume = dataAudio.GetVolume();
            audioSource.loop   = dataAudio.ShouldLoop();
        }

        // change pitch if necessary
        if (i_hashOptional.ContainsKey("pitch"))
        {
            float fPitch = (float)i_hashOptional["pitch"];
            audioSource.pitch = fPitch;
        }

        gameObject.transform.parent   = tf;
        gameObject.transform.position = tf.position;
        audioSource.Play();

        // add destroy script -- if the audio doesn't loop
        if (audioSource.loop == false)
        {
            m_fLifetime = clip.length + 0.1f;
            if (i_hashOptional.ContainsKey("Time"))
            {
                m_fLifetime = (float)i_hashOptional["Time"];
            }

            DestroyThis scriptDestroy = gameObject.AddComponent <DestroyThis>();
            scriptDestroy.SetLife(m_fLifetime);
        }
    }
Esempio n. 2
0
    //////////////////////////////////////////
    /// Start()
    //////////////////////////////////////////
    void Start()
    {
        TextMesh mesh = gameObject.GetComponent <TextMesh>();

        if (mesh)
        {
            Color colorText = Constants_OLD.GetConstant <Color>(TextColor);
            mesh.color = colorText;
        }
        else
        {
            Debug.LogError("Warning: Object has no TextMesh but trying to access it( " + gameObject.name + ")", gameObject);
        }
    }