Unity/UniRx/接触判定/侵食2D
提供: 初心者エンジニアの簡易メモ
接触じゃなくて通り抜けの場合
using UnityEngine; using UniRx; using UniRx.Triggers; using System; public class ColliderTrigger2dScene : MonoBehaviour { [SerializeField] ObservableTrigger2DTrigger landTrigger; void Start() { IObservable<Collider2D> landOnTriggerEnterAsObservable = landTrigger.OnTriggerEnter2DAsObservable(); IObservable<Collider2D> landOnTriggerStayAsObservable = landTrigger.OnTriggerStay2DAsObservable(); IObservable<Collider2D> landOnTriggerExitAsObservable = landTrigger.OnTriggerExit2DAsObservable(); landOnTriggerEnterAsObservable.Subscribe(collider => { Debug.Log("OnTriggerEnter2D collider.gameObject.name=" + collider.gameObject.name); // 接触object名 }); landOnTriggerStayAsObservable.Subscribe(collider => { Debug.Log("OnTriggerStay2D collider.gameObject.name=" + collider.gameObject.name); // 接触object名 }); landOnTriggerExitAsObservable.Subscribe(collider => { Debug.Log("OnTriggerExit2D collider.gameObject.name=" + collider.gameObject.name); // 接触object名 }); } }