Method for setting initial time of audioclip

Hi, I’m new here and sorry for my bad english.

Is possible in Unity to set initial time of audioclip that I want to play in audiosource?

For example:
my clip is playing in audiosource,
when I press GUI button the time of audioclip go forward 10 seconds…

thanks for reply :slight_smile:

Hi znajomyyy

do you play audio after 10sec push button?

I wrote UnityScript.

var audio;

function OnGUI () {
	if (GUI.Button (Rect (10,10, 100, 50), "Play")) {
		PlayMusic();
	}
}

function PlayMusic () {
	yield WaitForSeconds (10);
	audio.Play();
}

thanks, but your code is only for waiting before I play a clip… I want to change/set time of clip when it is playing. Like a song… When I press button forward on my CD player current time of song will increase.

I want to set audio.time (time in seconds), but I think it is read only property… Any ideas? :slight_smile:

if ((audio.clip.length - audio.time) >= 10.0) audio.time += 10.0;
else audio.time = audio.clip.length;

Source : Unity - Scripting API: AudioSource.time

EDIT :

When something is Read Only, unity explicitly states it in the documentation.

Case in point, clip.length :

Diviner thanks :slight_smile: it works perfectly :slight_smile: I was trying only this way: audio.time = 10.0 not audio.time += 10.0 :slight_smile: