Poison Zone WIP

This commit is contained in:
szczuras4
2025-06-04 17:31:43 +02:00
parent 00e0a709c7
commit 002cca32bb
8 changed files with 3114 additions and 779 deletions

View File

@@ -864,6 +864,52 @@ namespace Beyond
ThirdPersonController._rigidbody.MovePosition(t.position);
ThirdPersonController._rigidbody.MoveRotation(t.rotation);
}
public void PlaySingleSound(AudioClip clipToPlay, bool destroyAfterPlaying = true)
{
// Opcjonalne opóŸnienie na starcie poziomu, aby unikn¹æ "spamowania" dŸwiêkami
if (Time.timeSinceLevelLoad < 0.5f && clipToPlay != null)
{
// Mo¿esz chcieæ to odkomentowaæ, jeœli dŸwiêki na starcie s¹ problemem
// return;
}
if (this.audioSource == null) // this.audioSource to pole GameObject (prefab) w Player.cs
{
Debug.LogWarning("Player's 'audioSource' (GameObject prefab) is not assigned in Inspector. Cannot play sound: " + (clipToPlay ? clipToPlay.name : "Unknown clip"));
return;
}
if (clipToPlay == null)
{
Debug.LogWarning("Attempted to play a null AudioClip.");
return;
}
// Instancjonowanie prefabu dŸwiêkowego
// Upewnij siê, ¿e prefab 'audioSource' ma komponent AudioSource
GameObject audioObjectInstance = Instantiate(this.audioSource, transform.position, transform.rotation);
AudioSource sourceComponent = audioObjectInstance.GetComponent<AudioSource>();
if (sourceComponent != null)
{
// PlayOneShot jest dobre dla efektów, nie przerywa innych dŸwiêków na tym samym source,
// jeœli s¹ one odtwarzane przez .Play() i nie u¿ywaj¹ tego samego kana³u.
sourceComponent.PlayOneShot(clipToPlay);
if (destroyAfterPlaying)
{
// Niszczymy obiekt GameObject zawieraj¹cy AudioSource po zakoñczeniu odtwarzania klipu.
// Dodajemy ma³y bufor czasowy, aby upewniæ siê, ¿e dŸwiêk zd¹¿y siê odtworzyæ w ca³oœci.
Destroy(audioObjectInstance, clipToPlay.length + 0.1f);
}
}
else
{
Debug.LogWarning("The instantiated 'audioSource' prefab (from Player.cs) does not have an AudioSource component. Destroying instance.");
Destroy(audioObjectInstance); // Posprz¹taj, jeœli coœ posz³o nie tak
}
}
}
[System.Serializable]