public void OnLevelComplete() { StopAllCoroutines(); int scorePerCoin = 100; for (int i = 0; i < coinsCollected; i++) { score += scorePerCoin; } coinsCollected = 0; onUIUpdated.Raise(); }
private void Die() { bool isTouchingHazards = playerBody.IsTouchingLayers(LayerMask.GetMask("Hazards")); if (isTouchingHazards) { health = 0; onPlayerHealthChanged.Raise(); onPlayerDeath.Raise(); GameManager.Instance.OnPlayerDeath(); } }
public void PickupDust(int count) { float _prevDust = dustCount; if (!superMode) { dustCount = Mathf.Clamp(dustCount + count, 0, maxDust); } Director.GetManager <ScoreManager>().AddScore(count); if (dustCount != _prevDust) { OnDustCountChanged.Raise(); } }
private void Update() { if (Input.GetKeyDown(KeyCode.Tab)) { _onInventoryOpen.Raise(); } }
protected void OnTriggerEnter2D(Collider2D collision) { var rocket = collision.GetComponent <RocketController>(); if (rocket) { _gameOver.Raise(); } }
public void Damage(float amount) { currentHealth -= amount; OnPlayerHealthChanged.Raise(); if (currentHealth <= 0) { OnPlayerDeath.Raise(); } }
IEnumerator RunTimerEvent() { Init(); var now = DateTime.UtcNow; while (nextEvent < now) { eventTarget.Raise(); if (pauseEvent) { yield return(new WaitUntil(() => !pauseEvent)); } nextEvent = nextEvent.AddSeconds(timeTrigger); if (dateTimeInitializer != null) { dateTimeInitializer.Value = nextEvent; } } while (true) { yield return(new WaitForSeconds(SecondsForNextEvent)); while (pauseEvent) { yield return(new WaitUntil(() => !pauseEvent)); yield return(new WaitForSeconds(SecondsForNextEvent)); } eventTarget.Raise(); nextEvent = nextEvent.AddSeconds(timeTrigger); if (dateTimeInitializer != null) { dateTimeInitializer.Value = nextEvent; } } }
private void OnTriggerEnter(Collider other) { var player = other.GetComponent <PlayerController>(); if (player) { Debug.Log("Entering Dungeon"); _onDungeonEntered.Raise(); } }
private void OnTriggerEnter(Collider other) { Debug.Log("Triggered"); var player = other.GetComponent <PlayerController>(); if (player) { _onChestOpened.Raise(); _chestAnimator.SetTrigger("Open"); } }
private void OnTriggerEnter2D(Collider2D collision) { if (triggersLeft < 1) { return; } if (collision.gameObject.GetComponent <PlayerMovement>()) { triggersLeft--; GameManager.Instance.OnLevelEnd(); onLevelEnd.Raise(); } }
protected void Buy() { if (PurchaseCondition()) { if (currency.SpendCurrency(purchasePrice)) { Debug.Log("Purchase succeeded."); OnPurchaseSucceeded.Raise(); PurchaseSuccessful(); } else { Debug.Log("Purchase failed, not enough currency."); OnPurchaseFailed.Raise(); } } else { Debug.Log(ConditionMessage); OnPurchaseFailed.Raise(); } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); GUI.enabled = Application.isPlaying; ScriptableEvent e = target as ScriptableEvent; if (GUILayout.Button("Raise")) { e.Raise(); } }
private void ConfigFetchComplete(ConfigResponse response) { foreach (var config in remoteConfigs) { ConfigManager.FetchCompleted -= config.LoadConfig; } ConfigManager.FetchCompleted -= ConfigFetchComplete; OnRemoteConfigLoadComplete.Raise(); Debug.Log("Remote Config Fetch Complete."); }
// Start is called before the first frame update void Update() { if (Input.GetAxis("Fire1") > 0 && dustCount >= maxDust) { Debug.Log("Supermode Activated"); superMode = true; OnSupermodeEnabled.Raise(); } if (superMode) { RemoveDust(Director.GetManager <TimeManager>().deltaTime *maxDust / superModeDuration); } }
private void OnCollisionEnter2D(Collision2D collision) { if (collision.collider.GetComponent <DustBullet>()) { Destroy(gameObject); Director.GetManager <ScoreManager>().AddScore(5); OnEnemyDeathEvent.Raise(); } if (collision.collider.GetComponent <PlayerHealth>()) { Destroy(gameObject); collision.collider.GetComponent <PlayerHealth>().Damage(damage); } }
public void GetNextSentence() { StopAllCoroutines(); if (_currentSentenceIndex < _dialogueSentences.Length) { _text.text = ""; StartCoroutine(TypeSentence()); } else { _currentSentenceIndex = 0; _onDialogueFinished.Raise(); } }
public void RemoveDust(float dropped) { float _prevDust = dustCount; dustCount = Mathf.Clamp(dustCount - dropped, 0, maxDust); if (dustCount <= 0) { superMode = false; OnSupermodeDisabled.Raise(); } if (dustCount != _prevDust) { OnDustCountChanged.Raise(); } }
IEnumerator Start() { loadingBar.anchorMax = new Vector2(0, loadingBar.anchorMax.y); var initTime = Time.time; OnRemoteConfigLoadComplete.OnRaise += () => { IsRemoteConfigLoaded = true; }; OnSceneLoad.Raise(); var sw = new Stopwatch(); sw.Start(); yield return(new WaitUntil(() => CheckIfRemoteConfigLoaded(sw, 5000))); IsRemoteConfigLoaded = false; sw.Stop(); var asyncLoad = SceneManager.LoadSceneAsync(sceneName); asyncLoad.allowSceneActivation = false; // Wait until the asynchronous scene fully loads while (!asyncLoad.isDone || Time.time - initTime <= delay) { var progress = GetAsyncOperationTimeWithDelay(asyncLoad, initTime, delay); loadingBar.anchorMax = new Vector2(progress, loadingBar.anchorMax.y); loadingBarText.text = $"LOADING... {(int)(progress * 100)}%"; yield return(new WaitForEndOfFrame()); if (asyncLoad.progress >= 0.85f && progress >= 0.85f) { asyncLoad.allowSceneActivation = true; } } asyncLoad.allowSceneActivation = true; yield return(null); }
public void OnDoorClosed() { _onDoorClosed.Raise(); }
public void OnDoorOpened() { _onDoorOpened.Raise(); }
private void Awake() { player.transform.position = transform.position; onLevelStarted.Raise(); }
public void AddScore(int toAdd) { score += toAdd; ScoreChangedEvent.Raise(); }
public void PickUpDust(DustMote pocket) { OnDustPickedUpEvent.Raise(); dustController.PickupDust(pocket.dustValue); pocket.PickUp(this); }
private void Awake() { playerBody = GetComponent <CapsuleCollider2D>(); health = maxHealth; onPlayerHealthChanged.Raise(); }
// Start is called before the first frame update IEnumerator Start() { yield return(new WaitForEndOfFrame()); Queue <Wave> waveQueue = new Queue <Wave>(); for (int i = startFromWave; i < waves.Count; i++) { waveQueue.Enqueue(waves[i]); } List <EnemySpawner> activeSpawners = new List <EnemySpawner>(); List <EnemyDuster> activeEnemies = new List <EnemyDuster>(); if (waveQueue.Count > 0) { nextWave = waveQueue.Peek(); OnNextWaveReady.Raise(); } float startTimer = timeBeforeStart; while (startTimer > 0) { startTimer -= Director.GetManager <TimeManager>().deltaTime; yield return(new WaitForEndOfFrame()); } while (waveQueue.Count > 0) { //take first wave Wave currentWave = waveQueue.Dequeue(); //run through all the wave parts foreach (var part in currentWave.parts) { Queue <Vector2> positionQueue = new Queue <Vector2>(); if (part.ordered) { positionQueue = new Queue <Vector2>(part.area.GetOrderedPoints(part.enemyCount)); } else { for (int i = 0; i < part.enemyCount; i++) { positionQueue.Enqueue(part.area.GetRandomPoint(part.edge)); } } //spawn all enemies as intended for (int i = 0; i < part.enemyCount; i++) { Vector2 position = boundaries.ClampToBoundary(positionQueue.Dequeue()); if (part.followPlayer) { position += (Vector2)player.transform.position; } //add all enemies to a list of enemies var spawner = Instantiate(spawnerPrefab, position, Quaternion.identity); spawner.StartCount(2); activeSpawners.Add(spawner); spawner.OnEnemySpawn += (enemy) => { activeSpawners.Remove(spawner); activeEnemies.Add(enemy); enemy.OnKill = () => { activeEnemies.Remove(enemy); }; }; if (!part.instant) { float enemyTimer = timeBetweenEnemies; while (enemyTimer > 0) { enemyTimer -= Director.GetManager <TimeManager>().deltaTime; yield return(new WaitForEndOfFrame()); } } } float partTimer = timeBetweenEnemies; while (partTimer > 0) { partTimer -= Director.GetManager <TimeManager>().deltaTime; yield return(new WaitForEndOfFrame()); } } while (activeEnemies.Count > 0 || activeSpawners.Count > 0) { yield return(new WaitForEndOfFrame()); } if (waveQueue.Count > 0) { nextWave = waveQueue.Peek(); OnNextWaveReady.Raise(); } float waveTimer = timeBetweenWaves; while (waveTimer > 0) { waveTimer -= Director.GetManager <TimeManager>().deltaTime; yield return(new WaitForEndOfFrame()); } } OnLastWaveClear.Raise(); }
void ShootBullet(Vector2 direction) { OnShootEvent.Raise(); Instantiate(bulletPrefab, transform.position, Quaternion.identity).transform.up = direction; }