コード例 #1
0
ファイル: GameLogic.cs プロジェクト: CDR2003/PROTOTYPES
    void Start()
    {
        // Distance display
        _distance = new ReadOnlyReactiveProperty <float>(Observable.EveryUpdate().Select(_ =>
                                                                                         Vector3.Distance(player.transform.position, mob.transform.position)));
        _distance.SubscribeToText(this.distanceText);

        // Mob chase player every update
        Observable.EveryUpdate().Subscribe(_ =>
                                           mob.direction.Value = (player.transform.position - mob.transform.position).normalized);

        // Time sequence of 1/1, 1/2, 1/3, 1/4...
        var fracTimeSequence = Observable.Create <float>(observer =>
        {
            var i = 1;
            return(Scheduler.DefaultSchedulers.TimeBasedOperations.Schedule(System.TimeSpan.FromSeconds(this.initialTime / i), self =>
            {
                observer.OnNext(i % 2 == 0 ? 1.0f : -1.0f);
                i++;
                self(System.TimeSpan.FromSeconds(this.initialTime / i));
            }));
        });

        fracTimeSequence.Subscribe(_ => this.player.direction.Value = Vector3.Cross(Vector3.back, this.mob.direction.Value).normalized);
    }