Skip to content

Instantly share code, notes, and snippets.

@runewake2
Created December 17, 2016 01:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save runewake2/ad154ed075afef194d202b58321c84f6 to your computer and use it in GitHub Desktop.
Save runewake2/ad154ed075afef194d202b58321c84f6 to your computer and use it in GitHub Desktop.
Simulate occluded particle systems in Unity 3D.
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