private void GetNearestTurret() { var turrets = GameObject.FindGameObjectsWithTag("Turret"); GameObject closest = null; float distance = float.MaxValue; foreach (var t in turrets) { var dis = (t.transform.position - transform.position).magnitude; if (dis < distance) { distance = dis; closest = t; } } if (closest != null) { turretHealth = closest.GetComponent <TurretHealth> (); } turret = closest; }
void Awake() { //getting all the components on the object. Setting them before RUN state will be a better approach _Rotation = this.GetComponent <TurretRotation> (); _Raycast = this.GetComponent <RaycastHandler> (); _Shooting = this.GetComponent <ShootingSystem> (); _Health = this.GetComponent <TurretHealth> (); _Audio = this.GetComponent <AudioHandler> (); }
public override void OnStart() { base.OnStart(); if (target.Value == null) { return; } TurretHealth targetTower = target.Value.GetComponent <TurretHealth>(); string damageTaken = damage.ToString(); targetTower.TakeDamage(int.Parse(damageTaken)); }
private void Awake() { //_ = TryGetComponent(out _inputReciever); _ = TryGetComponent(out _weaponNormalGun); _ = TryGetComponent(out _weaponMissile); _ = TryGetComponent(out _weaponLaserBeam); _turretHealth = GetComponentInParent <TurretHealth>(); _laserSight = transform.parent.GetComponentInChildren <LineRenderer>(); _laserSight.gameObject.SetActive(false); // Disable by default for now //if (TryGetComponent<TurretLoader>(out var turretLoader)) //{ // turretLoader.OnReloadTurret += (_ammoType) => Reload(_ammoType); //} }
/// <summary> /// Called when player presses the use key /// </summary> private void useAction() { RaycastHit useHit; if (Physics.Raycast(_playerCamera.transform.position, _playerCamera.transform.forward, out useHit, _useRange)) { Transform target = useHit.transform; if (target.CompareTag("Door")) { DoorTrigger door = target.GetComponent <DoorTrigger>(); if (door != null) { door.Use(); } } if (target.CompareTag("Message Switch")) { MessageSwitch mSwitch = target.GetComponent <MessageSwitch>(); if (mSwitch != null) { mSwitch.Use(); } } if (target.CompareTag("Platform Switch")) { PlatformSwitch pSwitch = target.GetComponent <PlatformSwitch>(); if (pSwitch != null) { pSwitch.Use(); } } if (target.CompareTag("Turret")) { TurretHealth turretHealth = target.GetComponent <TurretHealth>(); if (turretHealth != null) { turretHealth.Die(); } } } }
bool playerLockOn; // Is the enemy locked onto the player? void Awake() { // Setting up the references. /*<--------Attack------------>*/ playerLockOn = true; if (GameObject.FindWithTag("Turret") != null) { turrets = GameObject.FindGameObjectsWithTag("Turret"); turret = turrets [0]; turretHealth = turret.GetComponent <TurretHealth> (); playerLockOn = false; } player = GameObject.FindGameObjectWithTag("Player"); playerHealth = player.GetComponent <PlayerHealth> (); enemyHealth = GetComponent <EnemyHealth>(); anim = GetComponent <Animator> (); /*<------- Movement ------------>*/ // Set up the references. nav = GetComponent <NavMeshAgent> (); }
void OnParticleCollision(GameObject other) { /*if (gameObject.tag.Equals("EarthShatter")) * { * Debug.Log("HEARTHSHATTER TAG: "+ part.transform.parent.parent.tag +" OTHER: "+other.tag); * //Debug.Log("ACERTOU COM O HEARTHSHATTER: "+other); * if (other.CompareTag("DragonP1") && part.transform.parent.parent.CompareTag("Player2")) * { * minionHealth = other.GetComponent<MinionHealth>(); * minionHealth.setDamage(part.transform.parent.parent.GetComponent<PlayerAttack1>().getHearthShakeDmg()); * minionHealth.wasHit = true; * Debug.Log("HEARTHSHATTER MINION: " + other); * } * else if (other.CompareTag("DragonP2") && part.transform.parent.parent.CompareTag("Player1")) * { * minionHealth = other.GetComponent<MinionHealth>(); * minionHealth.setDamage(part.transform.parent.parent.GetComponent<PlayerAttack1>().getHearthShakeDmg()); * minionHealth.wasHit = true; * Debug.Log("HEARTHSHATTER MINION: " + other); * } * * if (other.CompareTag("Player1") && part.transform.parent.parent.CompareTag("Player2")) * { * player = other.GetComponent<PlayerHealth>(); * int player1Res = player.getResistence(); * int player2Damage = part.transform.parent.parent.GetComponent<PlayerAttack1>().getHearthShakeDmg(); * Debug.Log("HEARTHSHATTER DMG: " + player2Damage); * int totalDamage = (int)(player2Damage - (player2Damage * (player1Res / 100.0f))); * Debug.Log("HEARTHSHATTER TOTAL DMG: " + totalDamage); * player.TakeDamage(totalDamage); * Debug.Log("HEARTHSHATTER PLAYER: " + other+"; ENEMY LIFE: "+player.getCurrentHealth()); * } * else if (other.CompareTag("Player2") && part.transform.parent.parent.CompareTag("Player1")) * { * player = other.GetComponent<PlayerHealth>(); * int player2Res = player.getResistence(); * int player1Damage = part.transform.parent.parent.GetComponent<PlayerAttack1>().getHearthShakeDmg(); * Debug.Log("HEARTHSHATTER DMG: " + player1Damage); * int totalDamage = (int)(player1Damage - (player1Damage * (player2Res / 100.0f))); * Debug.Log("HEARTHSHATTER TOTAL DMG: " + totalDamage); * player.TakeDamage(totalDamage); * Debug.Log("HEARTHSHATTER PLAYER: " + other + "; ENEMY LIFE: " + player.getCurrentHealth()); * } * * part.GetComponent<ParticleSystem>().Stop(); * return; * }*/ Debug.Log("Entrei no collision: " + other); if (other.CompareTag("DragonP1") && part.transform.parent.parent.CompareTag("Player2")) { minionHealth = other.GetComponent <MinionHealth>(); minionHealth.setDamage(part.transform.parent.parent.GetComponent <PlayerHealth>().getPlayerDamage()); minionHealth.wasHit = true; return; } else if (other.CompareTag("DragonP2") && part.transform.parent.parent.CompareTag("Player1")) { minionHealth = other.GetComponent <MinionHealth>(); minionHealth.setDamage(part.transform.parent.parent.GetComponent <PlayerHealth>().getPlayerDamage()); minionHealth.wasHit = true; return; } if (other.CompareTag("TurretP1") && part.transform.parent.parent.CompareTag("Player2")) { towerHeath = other.GetComponent <TurretHealth>(); towerHeath.TakeDamage(part.transform.parent.parent.GetComponent <PlayerHealth>().getPlayerDamage()); return; } else if (other.CompareTag("TurretP2") && part.transform.parent.parent.CompareTag("Player1")) { towerHeath = other.GetComponent <TurretHealth>(); towerHeath.TakeDamage(part.transform.parent.parent.GetComponent <PlayerHealth>().getPlayerDamage()); return; } // ALTERAR DANO DAS TORRES BASEADO NO DANO BASICO DE CADA PLAYER if (other.CompareTag("Player1") && part.transform.parent.parent.CompareTag("Player2")) { player = other.GetComponent <PlayerHealth>(); int player1Res = player.getResistence(); int player2Damage = part.transform.parent.parent.GetComponent <PlayerHealth>().getPlayerDamage(); Debug.Log("PLAYER DAMAGE: " + player2Damage); int totalDamage = (int)(player2Damage - (player2Damage * (player1Res / 100.0f))); Debug.Log("PLAYER TOTAL DAMAGE: " + totalDamage); player.TakeDamage(totalDamage); bool lifeSteal = part.transform.parent.parent.GetComponent <PlayerPowers>().getLifeStealStatus(); if (lifeSteal) { int percent = 35; part.transform.parent.parent.GetComponent <PlayerHealth>().addHealth((int)(totalDamage * (percent / 100.0f))); } return; } else if (other.CompareTag("Player2") && part.transform.parent.parent.CompareTag("Player1")) { player = other.GetComponent <PlayerHealth>(); int player2Res = player.getResistence(); int player1Damage = part.transform.parent.parent.GetComponent <PlayerHealth>().getPlayerDamage(); Debug.Log("PLAYER DAMAGE: " + player1Damage); int totalDamage = (int)(player1Damage - (player1Damage * (player2Res / 100.0f))); Debug.Log("PLAYER TOTAL DAMAGE: " + totalDamage); player.TakeDamage(totalDamage); bool lifeSteal = part.transform.parent.parent.GetComponent <PlayerPowers>().getLifeStealStatus(); if (lifeSteal) { int percent = 35; part.transform.parent.parent.GetComponent <PlayerHealth>().addHealth((int)(totalDamage * (percent / 100.0f))); } return; } }
/// <summary> /// Iniciando as variáveis no início do script. /// </summary> void Start() { this._myTransform = transform; this._fsm = new TurretStateMachine(this._myTransform); this._health = new TurretHealth(this._myTransform.FindChild("HealthText").GetComponent<TextMesh>()); }