Skip to content

Instantly share code, notes, and snippets.

@Protonz
Last active December 23, 2017 16:42
Show Gist options
  • Save Protonz/72ff882c942419aef8112c0c361240ba to your computer and use it in GitHub Desktop.
Save Protonz/72ff882c942419aef8112c0c361240ba to your computer and use it in GitHub Desktop.
using UnityEngine;
using UniRx.Triggers;
using UniRx;
public class DamageVolume : MonoBehaviour {
public bool IsNegateVolume = false;
void Start () {
Collider c = GetComponent<Collider>();
// Add this volume to the player
c.OnTriggerEnterAsObservable()
.Select(other => other.GetComponent<DamageVolumePlayer>())
.Where(damageVolumePlayer => damageVolumePlayer != null && damageVolumePlayer.CurrentDamageVolumes.Contains(this) == false )
.Subscribe(damageVolumePlayer =>
damageVolumePlayer.CurrentDamageVolumes.Add(this)
).AddTo(this);
// Remove this volume from the player
c.OnTriggerExitAsObservable()
.Select(other => other.GetComponent<DamageVolumePlayer>())
.Where(damageVolumePlayer => damageVolumePlayer != null && damageVolumePlayer.CurrentDamageVolumes.Contains(this) == true)
.Subscribe(damageVolumePlayer =>
damageVolumePlayer.CurrentDamageVolumes.Remove(this)
).AddTo(this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment