void UpdateTarget() { GameObject[] enemies = GameObject.FindGameObjectsWithTag(enemyTag); float shortestDistance = Mathf.Infinity; GameObject nearestEnemy = null; foreach (GameObject enemy in enemies) { float distanceToEnemy = Vector3.Distance(transform.position, enemy.transform.position); if (distanceToEnemy < shortestDistance) { shortestDistance = distanceToEnemy; nearestEnemy = enemy; } } if (nearestEnemy != null && shortestDistance <= range) { target = nearestEnemy.transform; targetEnemy = nearestEnemy.GetComponent <EnemyHealthScript>(); if (targetEnemy.GetHealth() <= 0f) { target = defaulttarget; } } else { target = defaulttarget; } }
// Update is called once per frame void Update() { if (Input.GetButtonDown("Fire1")) { Shoot(); } if (Input.GetButtonDown("Fire2")) { ShootBullet(); } void Shoot() { RaycastHit hit; if (Physics.Raycast(gunCam.transform.position, gunCam.transform.forward, out hit, range)) { Debug.Log(hit.transform.name); EnemyHealthScript target = hit.transform.GetComponent <EnemyHealthScript>(); if (target != null) { target.takeDamage(damage); } } } void ShootBullet() { GameObject bullet = Instantiate(bulletPrefab, gun.transform.position, gun.transform.rotation); bullet.transform.position = gun.transform.position + gun.transform.forward; } }
// Use this for initialization void Start() { ehs = GetComponent<EnemyHealthScript>(); baseMs = es.MoveSpeed; baseHp = ehs.maxHp; CheckStance(); }
// Use this for initialization void Start() { mainCamera = Camera.main; EnemyHealthScript enemyHealth = gameObject.GetComponentInParent <EnemyHealthScript>(); //finding the script with that contains health variables enemyHealth.OnHealthChanged += HealthChanged; // calling the public event since the camera needs to keep track of the health hpTransform = (RectTransform)gameObject.transform.Find("RemainingHealth").transform; //finding the green bar with the remaining health }
void Start() { damage = GameObject.Find("EmptyObject(Clone)").GetComponent <StoringVarScript> ().damage; material = GetComponent <SpriteRenderer> ().material; color = material.color; blinkTime = 0f; enemyHealth = gameObject.GetComponent <EnemyHealthScript> (); }
private void OnCollisionEnter(Collision collision) { if (collision.gameObject.tag == "Enemy") { EnemyHealthScript s = collision.gameObject.GetComponent <EnemyHealthScript>(); s.Damage(damage); } }
private void Start() { health = GetComponentInParent <EnemyHealthScript>(); if (!health.isActiveAndEnabled) { health.enabled = true; } }
// Use this for initialization void Start() { ds = door.GetComponent<DoorScript>(); es = boss.GetComponent<EnemyScript>(); ehs = boss.GetComponent<EnemyHealthScript>(); ps = VariableScript.scrPlayerScript1; speed = es.MoveSpeed; }
/// <summary> /// starts off the worm in a random direction /// </summary> public void Start() { vector = new Vector3(Random.Range(-360, 360), Random.Range(-360, 360), Random.Range(-360, 360)); this.transform.LookAt(vector); this.transform.Translate(Vector3.forward * Time.deltaTime); this.GetComponent <Collider>().enabled = true; health = this.gameObject.GetComponent <EnemyHealthScript>(); }
private void OnCollisionEnter2D(Collision2D other) { if (other.transform.gameObject.CompareTag("Enemy")) { hs = other.gameObject.GetComponent <EnemyHealthScript>(); hs.TakeHit(); Destroy(transform.gameObject); } }
private void OnCollisionEnter2D(Collision2D collision) { EnemyHealthScript enemyHealth = collision.gameObject.GetComponent <EnemyHealthScript>(); if (enemyHealth != null) { Damage(enemyHealth.maxHP); } }
private void OnTriggerEnter(Collider other) { if (other.tag != "Player" && harpoonFlying) { harpoonFlying = false; this.GetComponent <Rigidbody>().velocity = new Vector3(0, 0, 0); if (other.gameObject.tag == "ClamArmor") { //ClamShellScript s = other.gameObject.GetComponent<ClamShellScript>(); //s.OnHarpoonHit(); audioSource.clip = chitinImpactClip; audioSource.Play(); } if (other.gameObject.tag == "BarnacleArmor") { //BarnacleShellScript b = other.gameObject.GetComponent<BarnacleShellScript>(); //b.OnHarpoonHit(); audioSource.clip = chitinImpactClip; audioSource.Play(); } if (other.gameObject.tag == "Enemy") { EnemyHealthScript s = other.gameObject.GetComponent <EnemyHealthScript>(); s.Damage(damage); audioSource.clip = fleshImpactClip; audioSource.Play(); } if (other.gameObject.tag == "ClamCollider") { audioSource.clip = fleshImpactClip; audioSource.Play(); } if (other.gameObject.tag == "EnemyHarpoonable") { EnemyHealthScript s = other.gameObject.GetComponent <EnemyHealthScript>(); s.Damage(damage); audioSource.clip = fleshImpactClip; audioSource.Play(); } strikeJoint = gameObject.AddComponent <FixedJoint>(); if (other.attachedRigidbody) { strikeJoint.connectedBody = other.attachedRigidbody; } else { audioSource.clip = rockImpactClip; audioSource.Play(); stuckInTerrain = true; } } }
//someScript = GetComponent (ExampleScript); void OnTriggerEnter(Collider obj) { if (obj.gameObject.tag == "LevelObject") { Destroy (gameObject); } else if (obj.gameObject.tag == "Enemy") { healthScript = obj.gameObject.GetComponent<EnemyHealthScript>(); healthScript.damage = damage; } }
void Start() { deadCheck = (EnemyHealthScript)gameObject.GetComponent("EnemyHealthScript"); isDead = deadCheck.isDead; GameObject go = GameObject.FindGameObjectWithTag("Player"); target = go.transform; weaponTransform = transform.Find("attackBox"); script = GetComponent <ZombieAttack> (); }
//someScript = GetComponent (ExampleScript); void OnTriggerEnter(Collider obj) { if (obj.gameObject.tag == "LevelObject") { Destroy(gameObject); } else if (obj.gameObject.tag == "Enemy") { healthScript = obj.gameObject.GetComponent <EnemyHealthScript>(); healthScript.damage = damage; } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Space) && HarpoonConnected == true) { GameObject newPhysicsObject; newPhysicsObject = Instantiate(PhysicsPrefab, ClamShell.transform.position, ClamShell.transform.rotation, null); newPhysicsObject.GetComponent <Rigidbody>().AddRelativeForce(Vector3.forward * 1000); Destroy(ClamShell); EnemyHealthScript clamscript = ClamParent.GetComponent <EnemyHealthScript>(); clamscript.Vulnerable = true; HarpoonConnected = false; Destroy(gameObject); } }
void Damage(Transform enemy) { EnemyHealthScript eHp = enemy.GetComponent <EnemyHealthScript>(); if (eHp != null) { eHp.AddHealth(-damage); Debug.Log(eHp.GetHealth()); if (eHp.GetHealth() <= 0f) { enemy.gameObject.SetActive(true); } } }
public void UnstickFromTerrain() { if (TerrainAttachment != null) { Destroy(TerrainAttachment); GetComponent <Rigidbody>().AddRelativeForce(Vector3.up * 2000); EnemyHealthScript barnacleScript = BarnacleParent.GetComponent <EnemyHealthScript>(); barnacleScript.Vulnerable = true; HarpoonConnected = false; if (attachedHarpoon) { attachedHarpoon.GetComponent <HarpoonScript>().DetachHarpoon(); attachedHarpoon = null; } BarnacleParent.GetComponent <BarnacleScript>().Detach(); } }
void Awake() { anime = GetComponent <Animator>(); health = GetComponent <EnemyHealthScript>(); audioSource = GetComponent <AudioSource>(); player = GameObject.FindGameObjectWithTag("Player"); playerHealth = player.GetComponent <PlayerHealth>(); SetDefaultPosAndRot(); xPosition = transform.position.x + DistanceToMove; moveSpeedAnime = 0; //a = player.transform.position; enemyAttck = this; canMoveEnemyWithDelay = false; }
// Use this for initialization void Start () { enemyHs = gameObject.GetComponentInParent<EnemyHealthScript>(); if (enemyHs != null) { ShowPoint = enemyHs.DmgCount; GetComponent<TextMesh>().text = "-" + Mathf.RoundToInt(ShowPoint).ToString(); if (enemyHs.direction) { GetComponent<Rigidbody2D> ().AddForce (new Vector2 (Random.Range (100, 200), Random.Range (550, 750))); } else { GetComponent<Rigidbody2D> ().AddForce (new Vector2 (Random.Range (-100, 300), Random.Range (550, 750))); } transform.parent = null; } //假如傷害超過20點 → 產生暴擊效果 if (ShowPoint >= 20) { showT = 0.5f; StartCoroutine(BtoS ()); } StartCoroutine(showTime (showT)); }
void OnTriggerStay(Collider col) { if(timer > dmgInterval/Time.deltaTime){ timer = 0; phs = col.GetComponent<PlayerHealthScript>(); ehs = col.GetComponent<EnemyHealthScript>(); if(phs != null){ // Increase damage if player is too close if(Vector3.Distance(transform.position, col.transform.position) <= .35f){ timer = dmgInterval/Time.deltaTime; phs.HurtHealth(2); } phs.HurtHealth(1); } else if(ehs != null){ ehs.HurtHealth(3, this); } } }
// Update is called once per frame void FixedUpdate() { if (BrainsRemaining <= 0) { temptimer = temptimer + Time.fixedDeltaTime; if (temptimer < 14.5) { anim.Play(); } else { anim.Stop(); } if (Endbrain != null) { EnemyHealthScript endbrainhealthscript = Endbrain.GetComponent <EnemyHealthScript>(); endbrainhealthscript.Vulnerable = true; } } }
//void Update() //{ // if (takeDamage) // { // takeDamage = false; // } //} void OnTriggerEnter(Collider other) { //Debug.Log("Boom"); //take damage health_enemy = other.GetComponent <EnemyHealthScript>(); //disable enemyAttck other.GetComponent <EnemyAttck>().enabled = false; //take damage to player health_player.TakeDamage(1, 1); //take damage to enemy if (health_enemy != null) { health_enemy.ApplyDamage(100); } Instantiate(explosion, player.transform.position, Quaternion.identity); CameraShaker.Instance.ShakeOnce(1f, 1f, .05f, 1.2f); }
void OnCollisionEnter(Collision col) { if (col.gameObject.tag == "Enemy") { EnemyHealthScript ehs = col.gameObject.GetComponent <EnemyHealthScript> (); ehs.health -= 1; GameObject bhole = Instantiate(enemySphere, this.gameObject.transform.position, this.gameObject.transform.rotation) as GameObject; bhole.transform.parent = col.gameObject.transform; Destroy(this.gameObject); } else if (col.gameObject.tag == "Terrain" || col.gameObject.tag == "Untagged") { Destroy(this.gameObject); } else if (col.gameObject.tag == "Wall") { Destroy(this.gameObject); } }
void OnCollisionEnter(Collision collision) { bool destroyThis = false; bool armorImpact = false; if (Random.Range(0, 5) != 0) { destroyThis = true; } if (collision.gameObject.tag == "Enemy") { EnemyHealthScript s = collision.gameObject.GetComponent <EnemyHealthScript>(); s.Damage(damage); destroyThis = true; } if (collision.gameObject.tag == "EnemyHarpoonable") { EnemyHealthScript s = collision.gameObject.GetComponent <EnemyHealthScript>(); s.Damage(damage); destroyThis = true; } Debug.Log(collision.gameObject.tag); if (collision.gameObject.CompareTag("BarnacleArmor") || collision.gameObject.CompareTag("ClamArmor")) { armorImpact = true; } if (destroyThis) { GameObject i = Instantiate(impactPrefab, this.transform.position, Quaternion.identity); if (armorImpact) { i.GetComponent <LaserImpactScript>().armorImpact = true; } Destroy(this.gameObject); } }
void OnCollisionEnter2D(Collision2D collision) { // Collision with enemy NewEnemyScript enemy = collision.gameObject.GetComponent <NewEnemyScript> (); if (enemy != null) { // Kill the enemy EnemyHealthScript enemyHealth = enemy.GetComponent <EnemyHealthScript>(); if (enemyHealth != null) { enemyHealth.Damage(enemyHealth.hp, 0); } // AKA deal as much damage as the enemy's health. // Deals 1 damage to to the player. HealthScript playerHealth = this.GetComponent <HealthScript>(); if (playerHealth != null) { playerHealth.Damage(1, 0); } } }
void OnCollisionEnter(Collision collision) { if (lifetime >= armingTime) { Instantiate(impactPrefab, this.transform.position, Quaternion.identity); Destroy(this.gameObject); Collider[] objectsWithinExplosion = Physics.OverlapSphere(transform.position, 30.0f); foreach (Collider c in objectsWithinExplosion) { if (c.gameObject.tag == "Enemy") { EnemyHealthScript s = c.gameObject.GetComponent <EnemyHealthScript>(); s.Damage(damage); } if (c.gameObject.tag == "EnemyHarpoonable") { EnemyHealthScript s = c.gameObject.GetComponent <EnemyHealthScript>(); s.Damage(damage); } } } }
void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "Enemy") { if (other.GetComponent <EnemyHealthScript>() != null) { Debug.Log("Trigger ---> Enemy hit by launcher"); EnemyHealthScript enemy = other.GetComponent <EnemyHealthScript>(); if (enemy.gameObject.name.Contains("left")) { if (enemy.currentHealth > 0) { MoveUpwards.killConfirmed = true; Shoot.missedShotsAttemps = 0; Shoot.missedLeftShots = 0; Shoot.LeftShotHit = true; Shoot.LeftEnemyCount += 1; enemy.ApplyDamage(enemy.maxHealth); } } else if (enemy.gameObject.name.Contains("right")) { if (enemy.currentHealth > 0) { MoveUpwards.killConfirmed = true; Shoot.missedShotsAttemps = 0; Shoot.missedRightShots = 0; Shoot.RightShotHit = true; Shoot.RightEnemyCount += 1; enemy.ApplyDamage(enemy.maxHealth); } } } } }
//----------------------------------Enemy Taking Damage------------------- void OnTriggerEnter(Collider collider) { //Damage Animations enemyDamageAnimation = EnemyHealthScript.FindObjectOfType <EnemyHealthScript> (); blueplasmalaserDamage = bluePlasmaLaser.FindObjectOfType <bluePlasmaLaser>(); bluePlasmaLaser plasma = collider.gameObject.GetComponent <bluePlasmaLaser>(); basicLaserDamage = BasicLaserScript.FindObjectOfType <BasicLaserScript>(); BasicLaserScript laser = collider.gameObject.GetComponent <BasicLaserScript>(); shielddeflectorenergy = ShieldDeflectorEnergyBackScript.FindObjectOfType <ShieldDeflectorEnergyBackScript>(); ShieldDeflectorEnergyBackScript shieldDeflectEnergy = collider.gameObject.GetComponent <ShieldDeflectorEnergyBackScript>(); electricBoltDamage = ElectricBoltScript.FindObjectOfType <ElectricBoltScript> (); ElectricBoltScript electricBolt = collider.gameObject.GetComponent <ElectricBoltScript> (); Vector3 playerHitPos = collider.transform.position; float chanceEnemyHit = Random.Range(1, 100); if (EnemyHealth <= 0) { playercontroller.playerAnimator.SetBool("Evade", false); collider.enabled = false; } if (shieldDeflectEnergy && chanceEnemyHit < playerAccuracy) { enemyDamageAnimation.ReceiveDamage(shielddeflectorenergy.damage); Destroy(collider.gameObject); GameObject deflectenergyimpact = Instantiate(ShieldDeflectImpact, playerHitPos, Quaternion.identity) as GameObject; xp.GainXP(10); //smoke.SetActive(true); EnemyHealth = EnemyHealth - shielddeflectorenergy.damage * deflectorDamage; Debug.Log("Enemy health is " + EnemyHealth); //battlecontroller.enemyText.text = "Health: " + EnemyHealth; //SMOKE GRAPHICS if (EnemyHealth == 80) { Vector3 startPostion = transform.position + new Vector3(2, 2, 0); GameObject smokeHit = Instantiate(smoke, playerHitPos, Quaternion.identity) as GameObject; } if (EnemyHealth == 60) { Vector3 startPostion = transform.position + new Vector3(0, 0, 0); GameObject bigExplosi = Instantiate(bigExplosion, startPostion, Quaternion.identity) as GameObject; } if (EnemyHealth < 20) { Vector3 startPostion = transform.position + new Vector3(0, -.38f, 0.47f); GameObject smokeLot = Instantiate(lotSmoke, startPostion, Quaternion.identity) as GameObject; smokeLot.transform.parent = gameObject.transform; } if (EnemyHealth <= 0) { EnemyShip.SetActive(false); Vector3 startPostion = transform.position + new Vector3(0, 0, 0); GameObject deathexplosion = Instantiate(DeadExplosion, startPostion, Quaternion.identity) as GameObject; playercontroller.enemyIsDead = true; Character.Credits = Character.Credits + 100; PlayerPrefs.SetInt("PLAYER_CREDITS", Character.Credits); xp.UpdateDisplay(); //xp.GainXP(100); Invoke("EnemyDead", 6); } } if (plasma && chanceEnemyHit < playerAccuracy) { enemyDamageAnimation.ReceiveDamage(blueplasmalaserDamage.damage); Debug.Log("EnemyShip hit by plasma"); Destroy(collider.gameObject); //PLASMA IMPACT GameObject plas = Instantiate(PlasmaLaserImpact, playerHitPos, Quaternion.identity) as GameObject; xp.GainXP(10); //smoke.SetActive(true); EnemyHealth = EnemyHealth - blueplasmalaserDamage.damage; Debug.Log("Enemy health is " + EnemyHealth); //battlecontroller.enemyText.text = "Health: " + EnemyHealth; //SMOKE GRAPHICS if (EnemyHealth == 80) { Vector3 startPostion = transform.position + new Vector3(2, 2, 0); GameObject smokeHit = Instantiate(smoke, playerHitPos, Quaternion.identity) as GameObject; } if (EnemyHealth == 60) { Vector3 startPostion = transform.position + new Vector3(0, 0, 0); GameObject bigExplosi = Instantiate(bigExplosion, startPostion, Quaternion.identity) as GameObject; } if (EnemyHealth < 20) { Vector3 startPostion = transform.position + new Vector3(0, -.38f, 0.47f); GameObject smokeLot = Instantiate(lotSmoke, startPostion, Quaternion.identity) as GameObject; smokeLot.transform.parent = gameObject.transform; } if (EnemyHealth <= 0) { EnemyShip.SetActive(false); Vector3 startPostion = transform.position + new Vector3(0, 0, 0); GameObject deathexplosion = Instantiate(DeadExplosion, startPostion, Quaternion.identity) as GameObject; playercontroller.enemyIsDead = true; Character.Credits = Character.Credits + 100; PlayerPrefs.SetInt("PLAYER_CREDITS", Character.Credits); xp.UpdateDisplay(); //xp.GainXP(100); Invoke("EnemyDead", 6); } } if (laser && chanceEnemyHit < playerAccuracy) { enemyDamageAnimation.ReceiveDamage(basicLaserDamage.damage); Debug.Log("EnemyShip hit by laser"); Destroy(collider.gameObject); //LAserIMPACT GameObject bLImpact = Instantiate(BlueLaserImpact, playerHitPos, Quaternion.identity) as GameObject; xp.GainXP(10); //smoke.SetActive(true); EnemyHealth = EnemyHealth - basicLaserDamage.damage; Debug.Log("Enemy health is " + EnemyHealth); //battlecontroller.enemyText.text = "Health: " + EnemyHealth; //SMOKE GRAPHICS if (EnemyHealth == 80) { Vector3 startPostion = transform.position + new Vector3(2, 2, 0); GameObject smokeHit = Instantiate(smoke, startPostion, Quaternion.identity) as GameObject; } if (EnemyHealth == 60) { Vector3 startPostion = transform.position + new Vector3(0, 0, 0); GameObject bigExplosi = Instantiate(bigExplosion, startPostion, Quaternion.identity) as GameObject; } if (EnemyHealth < 20) { Vector3 startPostion = transform.position + new Vector3(0, -.38f, 0.47f); GameObject smokeLot = Instantiate(lotSmoke, startPostion, Quaternion.identity) as GameObject; smokeLot.transform.parent = gameObject.transform; } if (EnemyHealth <= 0) { if (PlayerPrefs.GetString("WHOS_ATTACKING") == "NGC1300BOSS") { EnemyShip.SetActive(false); Vector3 startPostion = transform.position + new Vector3(0, 0, 0); GameObject deathexplosion = Instantiate(DeadExplosion, startPostion, Quaternion.identity) as GameObject; playercontroller.enemyIsDead = true; Character.Credits = Character.Credits + 100; PlayerPrefs.SetInt("PLAYER_CREDITS", Character.Credits); xp.UpdateDisplay(); //xp.GainXP(100); Invoke("BossEnemyDead", 6); } EnemyShip.SetActive(false); Vector3 startPostion2 = transform.position + new Vector3(0, 0, 0); GameObject deathexplosion2 = Instantiate(DeadExplosion, startPostion2, Quaternion.identity) as GameObject; playercontroller.enemyIsDead = true; Character.Credits = Character.Credits + 100; PlayerPrefs.SetInt("PLAYER_CREDITS", Character.Credits); xp.UpdateDisplay(); //xp.GainXP(100); DropItem.DROPITEM = 1; Invoke("EnemyDead", 6); } } if (electricBolt && chanceEnemyHit < playerAccuracy) { enemyDamageAnimation.ReceiveDamage(electricBoltDamage.damage); Debug.Log("EnemyShip hit by plasma"); Destroy(collider.gameObject); //Electric Bolt IMPACT GameObject electricImpact = Instantiate(ElectricBoltImpact, playerHitPos, Quaternion.identity) as GameObject; xp.GainXP(10); //smoke.SetActive(true); EnemyHealth = EnemyHealth - electricBoltDamage.damage; Debug.Log("Enemy health is " + EnemyHealth); playercontroller.evade = 100f; //battlecontroller.enemyText.text = "Health: " + EnemyHealth; //SMOKE GRAPHICS if (EnemyHealth == 80) { Vector3 startPostion = transform.position + new Vector3(2, 2, 0); GameObject smokeHit = Instantiate(smoke, startPostion, Quaternion.identity) as GameObject; } if (EnemyHealth == 60) { Vector3 startPostion = transform.position + new Vector3(0, 0, 0); GameObject bigExplosi = Instantiate(bigExplosion, startPostion, Quaternion.identity) as GameObject; } if (EnemyHealth < 20) { Vector3 startPostion = transform.position + new Vector3(0, -.38f, 0.47f); GameObject smokeLot = Instantiate(lotSmoke, startPostion, Quaternion.identity) as GameObject; smokeLot.transform.parent = gameObject.transform; } if (EnemyHealth <= 0) { EnemyShip.SetActive(false); Vector3 startPostion = transform.position + new Vector3(0, 0, 0); xp.GainXP(50); GameObject deathexplosion = Instantiate(DeadExplosion, startPostion, Quaternion.identity) as GameObject; playercontroller.enemyIsDead = true; PlayerPrefs.SetInt("PLAYER_CREDITS", Character.Credits); xp.UpdateDisplay(); //xp.GainXP(100); Invoke("EnemyDead", 6); } } }
private void AttackEnemy() { EnemyHealthScript zh = (EnemyHealthScript)target.GetComponent("EnemyHealthScript"); zh.AdjustCurrentHealth(weaponDamage); }
void Awake() { // Retrieve the weapon only once weapons = GetComponentsInChildren <WeaponScript>(); enemyHealth = gameObject.GetComponent <EnemyHealthScript> (); }
// Use this for initialization void Start() { ps = VariableScript.scrPlayerScript1; ehs = boss.GetComponent<EnemyHealthScript>(); currentHP = ehs.curHp; defaultAttackSpeed = boss.GetComponent<Succubus>().attackRate; }
// Use this for initialization void Start() { ehs = GetComponent<EnemyHealthScript>(); child = transform.Find("Plane"); Vector3 temp = transform.position; temp.y = -5; // GameObject aura = (GameObject) Instantiate(VariableScript.objSmellyAura, temp, Quaternion.identity); // aura.transform.parent = transform; }