Example #1
0
    private void Start()
    {
        playerSession = FindObjectOfType <PlayerSession>();

        this.UpdateAsObservable()
        .Where(_ => Input.GetMouseButton(0))
        .Timestamp()
        .Where(x => x.Timestamp > timeToNextShot.AddSeconds(playerSession.GetTimeToNextShot()) && playerSession.GetAmmo() > 0)
        .Subscribe(x =>
        {
            timeToNextShot = x.Timestamp;
            fire();
        });

        this.UpdateAsObservable()
        .Where(_ => playerSession.GetAmmo() == 0)
        .ThrottleFirst(TimeSpan.FromSeconds(playerSession.GetTimeToReload()))
        .Delay(TimeSpan.FromSeconds(playerSession.GetTimeToReload()))
        .Subscribe(_ =>
        {
            playerSession.SetAmmo(playerSession.GetMaxAmmo());
        });
    }