Created
October 11, 2015 16:27
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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