Esempio n. 1
0
    void Start()
    {
        model.IsTurn
        .Subscribe(_ => view.ChangeDirection());

        view.IsTurn
        .Subscribe(a => {
            model.IsTurn.Value = a;
            Debug.Log(a);
        });

        view.coinCount
        .Subscribe(b => {
            model.coinCount.Value = b;
            Debug.Log("コインの数は" + b);
        });

        view.playerHP
        .Subscribe(c => {
            model.playerHP.Value = c;
            Debug.Log("HPは" + c);
            model.CalcPlayerHP();
        });

        this.UpdateAsObservable()
        .Where(_ => Input.GetKey(model.MOVELEFT_KEY))
        .Subscribe(_ => {
            view.Move(model.speed * -1);
            model.ChangeDirection(false);
        });

        this.UpdateAsObservable()
        .Where(_ => Input.GetKey(model.MOVERIGHT_KEY))
        .Subscribe(_ => {
            view.Move(model.speed);
            model.ChangeDirection(true);
        });
        this.UpdateAsObservable()
        .Where(_ => Input.GetKeyUp(model.MOVELEFT_KEY) || Input.GetKeyUp(model.MOVERIGHT_KEY))
        .Subscribe(_ => {
            view.MoveStop();
        });
        this.UpdateAsObservable()
        .Where(_ => Input.GetKeyDown(model.JUMP_KEY))
        .Subscribe(_ => {
            Debug.Log("JUMP");
            view.Junp();
        });
        this.UpdateAsObservable()
        .Where(_ => Input.GetKey(model.THROWSWORD_KEY))
        .Subscribe(_ => {
            view.ThrowSword();
        });
    }