void Awake() { player = GameObject.FindGameObjectWithTag("Player").transform; // on awake of game set target to player towerhp = player.GetComponent <Towerhealth>(); enemyHealth = GetComponent <Enemyhealth>(); nav = GetComponent <UnityEngine.AI.NavMeshAgent>(); // set the nav }
void Spawn() { if (counter <= 0 && enemyleft <= 0 && buildphase == false) { buildphase = true; Pointsystem.score += wave_reward[Wavesystem.wave_on]; if (Wavesystem.wave_on < 4) { Wavesystem.wave_on++; } phasemanager.Show(); } if (buildphase) { return; } if (playerHealth.currentHealth <= 0f || counter <= 0) { return; } int spawnPointIndex = Random.Range(0, spawnPoints.Length); //spawnpoint index random mize the index sub_enemy = (GameObject)Instantiate(enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation); // (enemy,position and rotation) sub_health = sub_enemy.GetComponent <Enemyhealth>(); sub_health.currentHealth = sub_health.currentHealth + enemy_health_increase[Wavesystem.wave_on]; counter--; }
//krock check private void OnTriggerEnter2D(Collider2D other) { //träff! hit = true; //ifall träffat fienden if (other.gameObject.CompareTag("Enemy")) { //fiende liv script kontroll Enemyhealth script = other.gameObject.GetComponent <Enemyhealth>(); if (script != null) { //gör skada script.Damage(arrowDamage); transform.parent = other.transform; Destroy(GetComponent <Rigidbody2D>()); Destroy(GetComponent <PolygonCollider2D>()); Destroy(this.gameObject, 1); } } else { transform.parent = other.transform; StickArrow(); //förstör pil efter 30 sekunder att den skjutits Destroy(this.gameObject, 30); } }
void HitTarget() { GameObject effectins = (GameObject)Instantiate(impact_effect, transform.position, transform.rotation); Destroy(effectins, 2f); //Destroy(target.gameObject); // gonna set this to do set amount of damage to enemies Enemyhealth enemyhp = target.gameObject.GetComponent <Enemyhealth>(); enemyhp.TakeDamage(attackdmg); Destroy(gameObject); return; }
void Shoot() { RaycastHit hit; if (Physics.Raycast(turretCam.transform.position, turretCam.transform.forward, out hit, range)) { Enemyhealth target = hit.transform.GetComponent <Enemyhealth>(); if (target != null) { target.TakeDamage(damagePerShot); } } }
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.3f) { if (direction > 0) { Enemyhealth eh = (Enemyhealth)target.GetComponent("Enemyhealth"); eh.AdjustCurrentHealth(-10); } } }
float timer; // timing for the attack so not fast private void Awake() { player = GameObject.FindGameObjectWithTag("Player"); towerhp = player.GetComponent <Towerhealth>(); enemyHealth = GetComponent <Enemyhealth>(); // get info from attack component }