Skip to content

Instantly share code, notes, and snippets.

@runewake2
Created December 17, 2016 01:42
Embed
What would you like to do?
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