public static void CreateVoxelParticle() { GameObject obj = new GameObject("Voxel Particle"); VoxelParticle vp = obj.AddComponent <VoxelParticle>(); ParticleSystem ps = obj.AddComponent <ParticleSystem>(); vp.particleSystem = ps; var emission = ps.emission; emission.enabled = false; var shape = ps.shape; shape.enabled = false; var renderer = ps.GetComponent <ParticleSystemRenderer>(); renderer.renderMode = ParticleSystemRenderMode.Mesh; GameObject t = GameObject.CreatePrimitive(PrimitiveType.Cube); renderer.mesh = t.GetComponent <MeshFilter>().sharedMesh; renderer.material = Resources.Load <Material>("Materials/DefaultVoxelParticleMat"); renderer.alignment = ParticleSystemRenderSpace.Local; GameObject.DestroyImmediate(t); }
public void Explode() { VoxelParticle voxParticle = GetComponent <VoxelParticle>(); if (voxParticle == null) { return; } if (!voxParticle.Valid) { return; } voxParticle.particleSystem.gravityModifier = gravity; for (int i = 0; i < voxParticle.voxelParticles.Length; i++) { voxParticle.voxelParticles[i].startLifetime = life; voxParticle.voxelParticles[i].remainingLifetime = Random.Range(life / 2, life); voxParticle.voxelParticles[i].velocity = new Vector3(Random.Range(-speed, speed), Random.Range(-speed, speed), Random.Range(-speed, speed)) + direction; } voxParticle.UpdateVoxels(); }
private void Start() { voxParticle = GetComponent <VoxelParticle>(); voxExplode = GetComponent <VoxelParticleExplode>(); }