Skip to content

Instantly share code, notes, and snippets.

@Naphier
Created October 11, 2015 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Naphier/8c53d9b498ef17ccdb55 to your computer and use it in GitHub Desktop.
Save Naphier/8c53d9b498ef17ccdb55 to your computer and use it in GitHub Desktop.
Simple script to set the playback speed of a particle system on application start Allows you to also lock that speed so it can't be changed by another script.
using UnityEngine;
/// <summary>
/// Simple script to set the playback speed of a particle system on application start
/// Allows you to also lock that speed so it can't be changed by another script.
/// </summary>
[RequireComponent(typeof(ParticleSystem))]
public class ParticleSystemSpeed : MonoBehaviour
{
public float speed = 1f;
public bool lockSpeed = false;
ParticleSystem psys;
void Start()
{
psys = gameObject.GetComponent<ParticleSystem>();
psys.playbackSpeed = speed;
}
void LateUpdate()
{
if (!lockSpeed)
return;
if (!Mathf.Approximately(psys.playbackSpeed, speed))
{
psys.playbackSpeed = speed;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment