public virtual void ApplyDamage(int Damage) { //DAMAGE if (Damage <= 0 || health <= 0) { return; } health -= Damage; if (health <= 0) { Death(); } if (OnDamaged != null) { //?. is a null reference check, it will not call the OnDamaged Delegate if there are no bound functions (meaning the delegate == null) OnDamaged?.Invoke(Damage); } else { //Debug.LogError(name + " No functions bound to OnDamaged delegate"); } }
public void ModifyEnemyCount(bool spawned) // basically this is where the true, false on the AIBase Start() and Death() { if (spawned) { Instance.EnemyCounter++; Debug.Log("Spawn"); } else { Debug.Log("Death"); Instance.EnemyCounter--; numberEnemyKilled++; // what we do is that we get the value (numberEnemyKilled) and put it onto the OnEnemyKilled since it takes an int OnEnemyKilled?.Invoke(numberEnemyKilled); // call the delegate (OnEnemyKilled) while passing through the date (numberEnemyKilled) } //OnEnemyCountChanged?.Invoke(manager.EnemyCounter); MulticastOneParam(int value) if (OnEnemyCountChanged != null) // this one the same than the top but with this you can check else { OnEnemyCountChanged(Instance.EnemyCounter); } else // what I know is that it will call this on every enemy spawned { Debug.LogError(name + " No functions bound to OnEnemyCountChanged"); } }
public void ModifyScoreUI(bool isNotImmortal) { // if player is not immortal, gain point / score if (isNotImmortal) { score++; OnWallsCollided?.Invoke(score); } else { // we want the immortality to be active only ONCE after death SetImmortality(false); } }
public void ModifyCoinsUI(int coinsAmount) { coins = coins + coinsAmount; OnCoinsCollided?.Invoke(coins); }
// This way it calls all the ColoredWalls. If you want one of them, has to ref the selected walls public void CheckPlayerColor(int NextTowerNumber) { OnTowerChecking?.Invoke(NextTowerNumber); // call the delegate functions that was subscribed }
// DELEGATES // This way it calls all the ColoredWalls. If you want one of them, has to ref the selected walls public void ModifyColoredWalls(int TowerNumber) { OnTowerPulling?.Invoke(TowerNumber); // call the delegate functions that was subscribed }