I'm making a game in Unity 3d, platform type, with scroll to the right. Now I am with the sound part of the game, and I don't know if there is something similar to the term that I put in the question. I try to explain it (I'm sure it has a name, but I don't know it, I've called it spriteSheet de sonido
).
In the case of sprites, we can use a single image that we split with the Unity3d image editor, to be able to use each "piece" of image, as a sequence, or a part of animation, platform, etc.
The question is if there is something similar to the spriteSheet, but for audio.
I have an audio that I can play at any time with:
public AudioClip miSonido;
void Start () {
source = GetComponent<AudioSource>();
}
void Update () {
if (Input.GetButtonDown("Fire1"))
{
source.Play(miSonido);
}
}
}
What I would be interested in is being able to access a part of that sound, and play it in a loop. In such a way that later, at another point (for example, when colliding with a tree that I have in one part of the stage) another part of the sound begins to be reproduced. But this being the same source file.
come on, what if there is something like this:
source.Play(miSonido, startAt, endAt, bucle)
(I made this last up, it's more or less to indicate what I'm looking for)
I shouldn't have a problem figuring out the possible time startAt
. endAt
I can use Audacity or another sound editor to locate the moment of time.
The first thing you should do in these cases is always to look in the Unity Manual if there is something that directly works for your problem. Since you are using Audio, we will look at Audio Source
Audio Source Manual
Here you can see the different functions and variables that it has, if you look closely there is a variable called time that indicates the time of the audio. And we can also see a function called SetScheduledEndTime.
Something like this should work: