public void PlayParticles(ParticleSpawnCommand command, Entity e, EntityManager manager) { command.particlesInstance = SpawnParticles(command.name); if (command.particlesInstance != null) { StartCoroutine(FollowEntity(command, e, manager)); } }
private IEnumerator FollowEntity(ParticleSpawnCommand command, Entity e, EntityManager manager) { float timeBegun = UnityEngine.Time.time; while ((command.life == 0) || (Time.time - timeBegun <= command.life)) { if (manager.Exists(e)) { if (command.name.Contains("Bullet") && !manager.HasComponent <Bullet>(e)) { break; } else { Translation translation = manager.GetComponentData <Translation>(e); command.particlesInstance.transform.position = translation.Value; } } else { break; } yield return(null); } if (command.life != 0) { yield return(new WaitForSeconds(10)); // cleanup, for particles that arnt looping } // create a death particle Vector3 position = command.particlesInstance.transform.position; Destroy(command.particlesInstance); if (command.deathParticleName != null && command.deathParticleName.Trim() != "") { command.particlesInstance = SpawnParticles(command.deathParticleName); if (command.particlesInstance != null) { command.particlesInstance.transform.position = position; Destroy(command.particlesInstance, command.deathParticleLife); } else { Debug.LogError("Failure to spawn particles: " + command.deathParticleName); } } }