Skip to content

Commit 0875db5

Browse files
committed
feat(Util): Detect loop for play one shot functions
1 parent 5f40276 commit 0875db5

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

Assets/JCSUnity/Scripts/Util/JCS_Util.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,9 @@ public static AudioSource PlayClipAtPoint(
14211421
audioSource.spatialBlend = spatialBlend;
14221422
audioSource.volume = volume;
14231423
audioSource.Play();
1424+
14241425
DestroyClip(audioSource);
1426+
14251427
return audioSource;
14261428
}
14271429

@@ -1434,6 +1436,9 @@ public static void DestroyClip(AudioSource source)
14341436
}
14351437
public static void DestroyClip(AudioSource source, AudioClip clip)
14361438
{
1439+
if (source.loop)
1440+
return;
1441+
14371442
Object.Destroy(source.gameObject, clip.length * ((Time.timeScale < 0.01f) ? 0.01f : Time.timeScale));
14381443
}
14391444

@@ -1453,23 +1458,28 @@ public static ParticleSystem PlayParticleAtPoint(ParticleSystem ps, Vector3 posi
14531458
if (ps == null)
14541459
return null;
14551460

1456-
ParticleSystem particleSystem = MonoBehaviour.Instantiate(ps);
1457-
particleSystem.gameObject.name = "One shot particle";
1458-
particleSystem.transform.position = position;
1459-
particleSystem.Play();
1460-
DestroyParticle(particleSystem, duration);
1461-
return particleSystem;
1461+
ParticleSystem newPS = MonoBehaviour.Instantiate(ps);
1462+
newPS.gameObject.name = "One shot particle";
1463+
newPS.transform.position = position;
1464+
newPS.Play();
1465+
1466+
DestroyParticle(newPS, duration);
1467+
1468+
return newPS;
14621469
}
14631470

14641471
/// <summary>
14651472
/// Destroy the particle by its duration.
14661473
/// </summary>
14671474
public static void DestroyParticle(ParticleSystem ps)
14681475
{
1469-
Object.Destroy(ps.gameObject, ps.main.duration);
1476+
DestroyParticle(ps, ps.main.duration);
14701477
}
14711478
public static void DestroyParticle(ParticleSystem ps, float duration)
14721479
{
1480+
if (ps.main.loop)
1481+
return;
1482+
14731483
Object.Destroy(ps.gameObject, duration);
14741484
}
14751485

0 commit comments

Comments
 (0)