Skip to content

Commit 6683b62

Browse files
committed
feat: Add destroy for clip and particle
1 parent ae43283 commit 6683b62

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

Assets/JCSUnity/Scripts/Util/JCS_Util.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,10 +1421,22 @@ public static AudioSource PlayClipAtPoint(
14211421
audioSource.spatialBlend = spatialBlend;
14221422
audioSource.volume = volume;
14231423
audioSource.Play();
1424-
Object.Destroy(gameObject, clip.length * ((Time.timeScale < 0.01f) ? 0.01f : Time.timeScale));
1424+
DestroyClip(audioSource);
14251425
return audioSource;
14261426
}
14271427

1428+
/// <summary>
1429+
/// Destroy the clip by its clip length.
1430+
/// </summary>
1431+
public static void DestroyClip(AudioSource source)
1432+
{
1433+
DestroyClip(source, source.clip);
1434+
}
1435+
public static void DestroyClip(AudioSource source, AudioClip clip)
1436+
{
1437+
Object.Destroy(source.gameObject, clip.length * ((Time.timeScale < 0.01f) ? 0.01f : Time.timeScale));
1438+
}
1439+
14281440
#endregion
14291441

14301442
#region Particle
@@ -1445,10 +1457,22 @@ public static ParticleSystem PlayParticleAtPoint(ParticleSystem ps, Vector3 posi
14451457
particleSystem.gameObject.name = "One shot particle";
14461458
particleSystem.transform.position = position;
14471459
particleSystem.Play();
1448-
Object.Destroy(particleSystem.gameObject, duration);
1460+
DestroyParticle(particleSystem, duration);
14491461
return particleSystem;
14501462
}
14511463

1464+
/// <summary>
1465+
/// Destroy the particle by its duration.
1466+
/// </summary>
1467+
public static void DestroyParticle(ParticleSystem ps)
1468+
{
1469+
Object.Destroy(ps.gameObject, ps.main.duration);
1470+
}
1471+
public static void DestroyParticle(ParticleSystem ps, float duration)
1472+
{
1473+
Object.Destroy(ps.gameObject, duration);
1474+
}
1475+
14521476
#endregion
14531477

14541478
#region Gameplay

0 commit comments

Comments
 (0)