// Use this for initialization void Start() { // Change HP text when value is changed hp.SubscribeToText(hpText); // Add animation ( we use LeanTween for this because it's a simple library that just works ) hp.Subscribe(_ => AnimateObj(hpText.gameObject)); // HP Bar hp.Subscribe(currentHP => { float normalizedHP = (currentHP / 100f); LeanTween.scaleX(hpBar, normalizedHP, 0.2f) .setEase(LeanTweenType.easeOutCirc); }); // HP Delta hp.Throttle(TimeSpan.FromMilliseconds(500)).Subscribe(delayedHP => { float normalizedHP = (delayedHP / 100f); LeanTween.scaleX(hpDelta, normalizedHP, 0.2f) .setEase(LeanTweenType.easeInQuad); }); // Button actions ------------------------ damageButton.onClick.AddListener(DamageHP); resetButton.onClick.AddListener(ResetHP); }
private void Start() { var yMin = (int)_bound.y; var yMax = (int)_bound.w + 1; var xMin = (int)_bound.x; var xMax = (int)_bound.z + 1; var tempCells = new List <List <Cell> >(); for (int yIndex = yMin; yIndex < yMax; yIndex++) { var rows = new List <Cell>(); for (int xIndex = xMin; xIndex < xMax; xIndex++) { var c = new Cell(xIndex, yIndex, Tilemap, FadingSpeed); rows.Add(c); } tempCells.Add(rows); } _cells = tempCells.Select(a => a.ToArray()).ToArray(); Observable.Range(0, MaxCpoints.Value).Subscribe(_ => AddCubePoints()).Dispose(); Observable.Range(0, MaxCParticles.Value).Subscribe(AddCubeParticles).Dispose(); MaxCpoints.Throttle(TimeSpan.FromMilliseconds(500)) .Subscribe(len => { if (len > _cPoints.Count) { var add = len - _cPoints.Count; Observable.Range(0, add).Subscribe(cp => AddCubePoints()).Dispose(); } else { var sub = _cPoints.Count - len; Observable.Range(0, sub).Subscribe(cp => _cPoints.RemoveAt(0)).Dispose(); } }).AddTo(this); MaxCParticles.Throttle(TimeSpan.FromMilliseconds(500)) .Subscribe(size => { if (size > _cubeParticles.Count) { var add = size - _cubeParticles.Count; Observable.Range(0, add).Subscribe(cp => AddCuubeParticle()).Dispose(); } else { var sub = _cubeParticles.Count - size; Observable.Range(0, sub).Subscribe(cp => { Destroy(_cubeParticles[0]); _cubeParticles.RemoveAt(0); }).Dispose(); } }).AddTo(this); }
// Use this for initialization void Start() { // Score Delta var scoreDelayed = score.Throttle(TimeSpan.FromMilliseconds(500)).ToReactiveProperty(); var scoreDelta = score.Select(x => x - scoreDelayed.Value); // Change deltaScoreText and format it so that if the number is positive it has a "+" in front of it scoreDelta.SubscribeToText(deltaScoreText, x => (x > 0 ? ("+" + x) : x.ToString())); // Add animation everytime score delta changes scoreDelta.Subscribe(_ => AnimateObj(deltaScoreText.gameObject)); scoreDelayed.Subscribe(delayedScore => { // Change text scoreText.text = delayedScore.ToString(); // You can also set by doing scoreDelayed.SubscribeToText(scoreText); // Start animation AnimateObj(scoreText.gameObject); // Clear deltaScore ocne we've updated the score deltaScoreText.text = ""; }); // Button actions ------------------------ addButton.onClick.AddListener(() => score.Value++); resetButton.onClick.AddListener(() => score.Value = 0); }
// Use this for initialization void Start() { // ---------------------------------- // Activate mainMenu // ---------------------------------- mainMenu.SetActive(true); endMenu.SetActive(false); gameMenu.SetActive(false); // ---------------------------------- // Setup scoreDelayed + scoreDelta // ---------------------------------- // Score Delayed scoreDelayed = score.Throttle(TimeSpan.FromSeconds(1)).ToReactiveProperty(); // Score Delta ( no need to have it as a private value since we're not gonna need to use it again in another function ) var scoreDelta = score.Select(x => x - scoreDelayed.Value); // Change deltaScoreText and format it so that if the number is positive it has a "+" in front of it scoreDelta.SubscribeToText(deltaScoreText, x => (x > 0 ? ("+" + x) : x.ToString())); // Add animation everytime score delta changes scoreDelta.Subscribe(_ => AnimateObj(deltaScoreText.gameObject)); scoreDelayed.Subscribe(delayedScore => { // Change text scoreText.text = delayedScore.ToString(); // You can also set it using scoreDelayed.SubscribeToText(scoreText); // Start animation AnimateObj(scoreText.gameObject); // Clear deltaScore ocne we've updated the score deltaScoreText.text = ""; }); // ---------------------------------- // Setup highscore ( and save values ) // ---------------------------------- int lastHighScore = PlayerPrefs.GetInt("highscore"); highscore = score.StartWith(lastHighScore).DistinctUntilChanged().Scan(int.MinValue, Math.Max).Do(x => PlayerPrefs.SetInt("highscore", x)).ToReactiveProperty(); // ---------------------------------- // Setup levels // ---------------------------------- level.SubscribeToText(levelText, x => "Level " + x.ToString()); // ---------------------------------- // Button actions // ---------------------------------- startButton.onClick.AddListener(StartGame); restartButton.onClick.AddListener(StartGame); }