Last active
December 23, 2017 16:42
-
-
Save Protonz/72ff882c942419aef8112c0c361240ba to your computer and use it in GitHub Desktop.
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 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