facebook twitter hatena line email

Unity/UniRx/接触判定/侵食2D

提供: 初心者エンジニアの簡易メモ
2023年3月6日 (月) 19:38時点におけるAdmin (トーク | 投稿記録)による版 (ページの作成:「<pre> using UnityEngine; using UniRx; using UniRx.Triggers; using System; public class ColliderTrigger2dScene : MonoBehaviour { [SerializeField] ObservableTrigge...」)

(差分) ←前の版 | 最新版 (差分) | 次の版→ (差分)
移動: 案内検索
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名
        });
    }
}