Hello, again.
I’m not a native English speaker, so please be generous with my grammatical faults.
I want to play two audio clip as background music.
The one(names ‘audioNormal’) has to play as game start, the other(names ‘audioFaster’) has to play when time remains less than half.
“audioNormal” clip is attached to Main Camera.
I thought “audioFaster” clip should be also atteched to Main Camera, too.
However, it never works.
Here’s my script and it is also attached Main Camera.
(The Image I attached is an Inspector window of Main Camera.)
#pragma strict
@script RequireComponent(AudioSource)
var audioNormal:AudioClip;
var audioFaster:AudioClip;
var time: GameObject; // need to get time infomation
function Start ()
{
audio.clip = audioNormal;
audio.Play();
time = gameObject.Find("GUIs/txtTime");
Debug.Log("1");
}
function Update ()
{
if(time.GetComponent(TimeGUI).startTime-Time.time < 31.0)
{
Debug.Log("2");
audio.Stop();
audio.clip = audioFaster;
Debug.Log("3");
audio.Play();
}
}
I used Debug.Log script to check the state of communication between two other scripts, and all of them have printed well.
Of course audio files doesn’t have any problem.
Now I am so confused.
What did I wrong? It’s too hard to find by myself.
Please help me.