예제 #1
0
    // Use this for initialization
    protected override void Awake()
    {
        base.Awake();

        var hinf = new RaycastHit();

        Grounded = Observable.EveryFixedUpdate()
                   .Select(_ => Physics.Raycast(RaycastOrigin, Vector3.down, out hinf, Level.Instance.DistBetweenAnchors, LayerMask.GetMask("Bounds", "Blocks", "Characters")))
                   .ToReadOnlyReactiveProperty(true);

        Grounded.AddTo(this);

        Grounded.Subscribe(x => Anim.SetBool("Falling", !x));

        ObservableHP = this.ObserveEveryValueChanged(x => x.CurHp)
                       .ToReadOnlyReactiveProperty(CurHp);

        IsDead = ObservableHP
                 .Select(x => x <= 0)
                 .ToReadOnlyReactiveProperty(false);

        Rb.OnCollisionEnterAsObservable()
        .Select(c => c.collider.GetComponentInParent <GameCharacter>())
        .Where(gc => gc && (gc.transform.position - transform.position).y < -Level.Instance.DistBetweenAnchors * .5f)
        .TakeUntil(IsDead.Where(x => x))
        .Subscribe(gc =>
        {
            target.Value = gc;
            gc.GetHit();
            Rb.AddForce(Vector3.up * 3.5f, ForceMode.Impulse);
        })
        .AddTo(this);
    }