SpawnEffect.cs 940 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class SpawnEffect : MonoBehaviour {
  5. public float spawnEffectTime = 2;
  6. public float pause = 1;
  7. public AnimationCurve fadeIn;
  8. ParticleSystem ps;
  9. float timer = 0;
  10. Renderer _renderer;
  11. int shaderProperty;
  12. void Start ()
  13. {
  14. shaderProperty = Shader.PropertyToID("_cutoff");
  15. _renderer = GetComponent<Renderer>();
  16. ps = GetComponentInChildren <ParticleSystem>();
  17. var main = ps.main;
  18. main.duration = spawnEffectTime;
  19. ps.Play();
  20. }
  21. void Update ()
  22. {
  23. if (timer < spawnEffectTime + pause)
  24. {
  25. timer += Time.deltaTime;
  26. }
  27. else
  28. {
  29. ps.Play();
  30. timer = 0;
  31. }
  32. _renderer.material.SetFloat(shaderProperty, fadeIn.Evaluate( Mathf.InverseLerp(0, spawnEffectTime, timer)));
  33. }
  34. }