// Start is called before the first frame update void Start() { mainCamera = Camera.main; OnEnemyExited += (whoExited) => playerHealth.AdjustHealth(); PlayerHealth.OnHealthChanged += (newHealth) => { if (newHealth <= 0) { SceneManager.LoadScene(gameOverSceneName); } }; OnMoneyChanged += (oldMoney, newMoney) => playerMoneyTextElement.text = ((Int32)newMoney).ToString("C"); Money = Money; towerGrid = new TowerGrid(gridWidth, gridHeight, gridScale, gridOrigin.transform.position, gridDisabledPositions); mouseObserver = GetComponent <MouseObserverBevahior>(); mouseObserver.OnMouseDrag += MouseDrag; mouseObserver.OnMousePress += MousePress; mouseObserver.OnMouseClick += MouseClick; SetupWaves(); StartCoroutine("SpawnWaves"); CreateTowerPlacementLineRenderers(); CreateEnemyPathLineRenderer(); }
private void OnTriggerEnter2D(Collider2D collision) { PlayerHealth playerHealth = collision.gameObject.GetComponent <PlayerHealth>(); if (playerHealth == null) { return; } playerHealth.AdjustHealth(damage); }
private void Heal() { float distance = Vector3.Distance(player.transform.position, transform.position); //Debug.Log ("Heal Zone" + distance); if (distance < 13.0f) { PlayerHealth ph = (PlayerHealth)player.GetComponent("PlayerHealth"); ph.AdjustHealth(healAmount); } }
private void Attack() { float distance = Vector3.Distance(target.transform.position, transform.position); Vector3 dir = (target.transform.position - transform.position).normalized; float direction = Vector3.Dot(dir, transform.forward); Debug.Log(direction); if (distance < 2.5f) { if (direction > 0) { PlayerHealth playerHealth = (PlayerHealth)target.GetComponent("PlayerHealth"); playerHealth.AdjustHealth(-10); } } }
private void Attack() { float distance = Vector3.Distance(target.transform.position, transform.position); Vector3 dir = (target.transform.position - transform.position).normalized; float direction = Vector3.Dot(dir, transform.forward); //Debug.Log ("Enemy" + direction); if (distance < 3.0f) { if (direction > 0.2) { PlayerAttack pa = (PlayerAttack)target.GetComponent("PlayerAttack"); Debug.Log("enemy attack"); PlayerHealth ph = (PlayerHealth)target.GetComponent("PlayerHealth"); ph.AdjustHealth(-10); } } }