protected override IDisposable Die() { Rb.DOKill(); Rb.gameObject.layer = LayerMask.NameToLayer("Ignore Raycast"); Anim.SetTrigger("Die"); if (deathSound) { SoundController.Play(deathSound.name); } return(transform.ObserveEveryValueChanged(x => x.position.y) // если труп куда-то улетел ... .AsUnitObservable() .SkipUntil(Observable.TimerFrame(2)) .Delay(TimeSpan.FromSeconds(.5f)) .Merge(Observable.Timer(TimeSpan.FromSeconds(2)).AsUnitObservable()) //... или прошло 2 секунды ... .Take(1) .Subscribe(_ => { DOTween.Sequence() .Append(GetComponentInChildren <Renderer>()?.material.DOFade(0, 1f)) //... фейдим материал в 0 и удаляем геймобджект .AppendCallback(() => Destroy(gameObject)); }) .AddTo(this)); }
protected IObservable <Unit> Move(Dir dir, float duration) { RotateTo(dir); var res = Observable.ReturnUnit(); if (dir == Dir.up || dir == Dir.down) { return(res); } return(res .Do(_ => { var tgt = null as Transform; switch (dir) { case Dir.left: tgt = Level.Instance.PreviousAnchor(transform.position); break; case Dir.right: tgt = Level.Instance.NextAnchor(transform.position); break; } Rb.DOKill(); movingSequence?.Kill(); movingSequence = DOTween.Sequence() .AppendCallback(() => Anim.SetBool("Moving", true)) .Append(Rb.DOMoveX(tgt.position.x, duration).SetEase(Ease.OutSine)) .AppendInterval(duration * .5f) .AppendCallback(() => Anim.SetBool("Moving", false)); }) .Delay(TimeSpan.FromSeconds(duration * .5f))); }