Created
December 17, 2016 01:42
-
-
Save runewake2/ad154ed075afef194d202b58321c84f6 to your computer and use it in GitHub Desktop.
Simulate occluded particle systems in Unity 3D.
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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Blizzard : MonoBehaviour { | |
public float verticleCeiling = 100; | |
public ParticleSystem[] blizzardEmitters; | |
// Use this for initialization | |
void Start () { | |
} | |
// Update is called once per frame | |
void Update () { | |
foreach (var particleSystem in blizzardEmitters) | |
{ | |
Ray ray = new Ray(particleSystem.transform.position + Vector3.up * verticleCeiling, Vector3.down); | |
RaycastHit hit; | |
if (Physics.Raycast(ray, out hit, verticleCeiling)) | |
{ | |
particleSystem.enableEmission = false; | |
} | |
else | |
{ | |
particleSystem.enableEmission = true; | |
} | |
} | |
} | |
void OnDrawGizmos() | |
{ | |
Gizmos.color = Color.red; | |
foreach (var particleSystem in blizzardEmitters) | |
{ | |
Gizmos.DrawRay(particleSystem.transform.position + Vector3.up*verticleCeiling, Vector3.down); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment