private HealthScript targetHealthScript; // The target's health script #endregion Fields #region Methods protected override void ApplyEffect() { // Apply damage to the target (will happen once per tick) if(target) { // Check if target is still alive targetHealthScript = target.GetComponent<HealthScript>(); // Damage() is part of HealthScript targetHealthScript.Damage(amount); // Apply damage to the target (mitigation is handled by HealthScript) } else { // Target is dead, get rid of the DoT base.EndEffect(); } }
void OnCollisionEnter2D(Collision2D collision) { Destroy(gameObject); var shotTransform = Instantiate(explosion) as Transform; shotTransform.position = transform.position; shotTransform.localScale = new Vector3(0.5f, 0.5f, 0.5f); HealthScript collider = collision.gameObject.GetComponent <HealthScript>(); if (collider != null) { collider.Damage(11); } }
void OnTriggerEnter2D(Collider2D otherCollider) { // Is this a shot? ShotScript shot = otherCollider.gameObject.GetComponent <ShotScript>(); if (shot != null) { // Avoid friendly fire if (shot.isEnemyShot != isEnemy) { Damage(shot.damage); // Destroy the shot Destroy(shot.gameObject); // Remember to always target the game object, otherwise you will just remove the script if (shot.areaDamage) { // 'Splosion! SpecialEffectsHelper.Instance.Explosion(transform.position); SoundEffectsHelper.Instance.MakeExplosionSound(); Vector3 center = transform.position; Collider2D[] hitColliders = Physics2D.OverlapCircleAll(center, shot.explosionArea); foreach (var hitCollider in hitColliders) { // Collision with enemy EnemyScript enemy = hitCollider.gameObject.GetComponent <EnemyScript>(); if (enemy != null) { // Damage the enemy HealthScript enemyHealth = enemy.GetComponent <HealthScript>(); if (enemyHealth != null) { enemyHealth.Damage(enemyHealth.hp); } } } } else { ExplosionAnimation(shot.ExplosionPrefab); SoundEffectsHelper.Instance.MakeDamageSound(); } } } }
private void OnCollisionEnter(Collision collision) { Debug.Log("projectile hit"); if (collision.collider.gameObject.tag == "PlayerProjectile") { if (enemyType == Type.Utility) { Explode(); } else { enemyHealthSystem.Damage(1); } Destroy(collision.collider.gameObject); } }
void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.name == "EndLevel") { Application.LoadLevel("Scene 2"); } if (collision.gameObject.name == "EndLevel1") { Application.LoadLevel("Scene 3"); } if (collision.gameObject.name == "EndLevel2") { Application.LoadLevel("Scene 4"); } if (collision.gameObject.name == "Pipe1" || collision.gameObject.name == "Pipe2") { ui.GetComponent <MenuScript>().GameOver(); Invoke("Replay", 0.5f); Destroy(gameObject); } if (collision.gameObject.tag == "Ground") { grounded = true; jumped = true; } bool damagePlayer = false; //столкновение с врагом EnemyScript enemy = collision.gameObject.GetComponent <EnemyScript>(); if (enemy != null) { //смерть врага HealthScript enemyHealth = enemy.GetComponent <HealthScript>(); damagePlayer = true; //повреждение у игрока if (damagePlayer) { HealthScript playerHealth = this.GetComponent <HealthScript>(); if (playerHealth != null) { playerHealth.Damage(playerHealth.hp); } } } }
void OnCollisionEnter2D(Collision2D collision) { bool damagePlayer = false; // зіткнення з ворогом EnemyScript enemy = collision.gameObject.GetComponent <EnemyScript>(); if (enemy != null) { // Вбий ворога HealthScript enemyHealth = enemy.GetComponent <HealthScript>(); if (enemyHealth != null) { enemyHealth.Damage(enemyHealth.hp); } damagePlayer = true; } // Collision with the boss BossScript boss = collision.gameObject.GetComponent <BossScript>(); if (boss != null) { // Бос теж втрачає деякий к.с. HealthScript bossHealth = boss.GetComponent <HealthScript>(); if (bossHealth != null) { bossHealth.Damage(5); } damagePlayer = true; } // Пошкодження гравця if (damagePlayer) { HealthScript playerHealth = this.GetComponent <HealthScript>(); if (playerHealth != null) { playerHealth.Damage(1); } } }
void OnCollisionEnter2D(Collision2D collision) { bool damagePlayer = false; // Collision with enemy EnemyScript enemy = collision.gameObject.GetComponent <EnemyScript>(); if (enemy != null) { // Kill the enemy HealthScript enemyHealth = enemy.GetComponent <HealthScript>(); if (enemyHealth != null) { enemyHealth.Damage(enemyHealth.hp); } damagePlayer = true; } // Collision with the boss BossScript boss = collision.gameObject.GetComponent <BossScript>(); if (boss != null) { // Boss lose some hp too HealthScript bossHealth = boss.GetComponent <HealthScript>(); if (bossHealth != null) { bossHealth.Damage(5); } damagePlayer = true; } // Damage the player if (damagePlayer) { HealthScript playerHealth = this.GetComponent <HealthScript>(); if (playerHealth != null) { playerHealth.Damage(1); } } }
void OnCollisionEnter2D(Collision2D collision) { EnemyScript enemy = collision.gameObject.GetComponent <EnemyScript> (); if (enemy != null) { HealthScript enemyHealth = enemy.GetComponent <HealthScript>(); if (enemyHealth != null) { enemyHealth.Damage(enemyHealth.HealthPoints); } HealthScript playerHealth = this.GetComponent <HealthScript>(); if (playerHealth != null) { playerHealth.Damage(enemy.CollisionDamage); } } }
void OnCollisionEnter2D(Collision2D collision) { bool damagePlayer = false; // Collision with enemy EnemyScript enemy = collision.gameObject.GetComponent <EnemyScript>(); if (enemy != null) { // Kill the enemy HealthScript enemyHealth = enemy.GetComponent <HealthScript>(); if (enemyHealth != null) { enemyHealth.Damage(1); } damagePlayer = true; } AsteroidScript asteroid = collision.gameObject.GetComponent <AsteroidScript>(); if (asteroid != null) { // Kill the enemy HealthScript asteroidHealth = asteroid.GetComponent <HealthScript>(); if (asteroidHealth != null) { asteroidHealth.Damage(1); } damagePlayer = true; } // Damage the player if (damagePlayer) { HealthScript playerHealth = this.GetComponent <HealthScript>(); if (playerHealth != null) { playerHealth.Damage(1); } } }
void OnCollisionEnter2D(Collision2D collision) { bool damagePlayer = false; // Collision with enemy EnemyScript enemy = collision.gameObject.GetComponent <EnemyScript>(); if (enemy != null) { // Kill the enemy HealthScript enemyHealth = enemy.GetComponent <HealthScript>(); if (enemyHealth != null) { enemyHealth.Damage(enemyHealth.hp); } damagePlayer = true; } // Damage the player if (damagePlayer) { HealthScript playerHealth = this.GetComponent <HealthScript>(); if (playerHealth.hp == 1) { restartButton.SetActive(true); } if (playerHealth != null) { playerHealth.Damage(1); } } /*TimeStopScript item = collision.gameObject.GetComponent<TimeStopScript>(); * if(item != null) * { * System.Console.WriteLine("hit an item"); * Destroy(item.gameObject); * return; * }*/ }
public void triggerBomb() { SpecialEffectsHelper.Instance.Bomb(player.transform.position); bombUi.SetActive(false); Collider2D[] hits = Physics2D.OverlapCircleAll( player.transform.position, 10f, 1 << LayerMask.NameToLayer("Enemies") // colide only with layer Enemies ); foreach (Collider2D collider in hits) { HealthScript health = collider.gameObject.GetComponent <HealthScript>(); if (health != null) { health.Damage(20); } } player.gameObject.GetComponent <PlayerScript>().nbBombs--; SoundEffectsHelper.Instance.MakePowerUpSound(); }
private void DealDamage() { _dealtDamage = true; Collider[] targets = Physics.OverlapSphere(transform.position, _damageRadius); // get all of the enemies within a radius around the spawned hand foreach (Collider target in targets) // make the hands deal damage { if ((1 << target.gameObject.layer) == _enemyLayer || (1 << target.gameObject.layer) == _bossLayer) { continue; } HealthScript playerHealth = GameMaster.instance.Player.GetComponent <HealthScript>(); if (playerHealth == null) { continue; } Debug.Log($"damaged player: {playerHealth.gameObject.name}"); playerHealth.Damage(_damage); // damage the player if they are within the radius } }
void OnCollisionEnter2D(Collision2D collision) { bool damagePlayer = false; // Collision with enemy EnemyScript enemy = collision.gameObject.GetComponent <EnemyScript>(); if (enemy != null) { // Kill the enemy /* * HealthScript enemyHealth = enemy.GetComponent<HealthScript>(); * if (enemyHealth != null) enemyHealth.Damage(0); */ ZombieScript zombie = collision.gameObject.GetComponent <ZombieScript>(); if (zombie != null) { zombie.stopZombie(); } damagePlayer = true; } Door door = collision.gameObject.GetComponent <Door>(); if (door != null) { // Hit a door! GameManager.instance.LoadLevelWithCoords(door.nextX, door.nextY); } // Damage the player if (damagePlayer) { HealthScript playerHealth = this.GetComponent <HealthScript>(); if (playerHealth != null) { playerHealth.Damage(1); } } }
private void OnTriggerEnter(Collider other) { // DealDamage(); if (_dealtDamage == false) { if ((1 << other.gameObject.layer) == _enemyLayer || (1 << other.gameObject.layer) == _bossLayer) { return; } HealthScript playerHealth = GameMaster.instance.Player.GetComponent <HealthScript>(); if (playerHealth == null || other.CompareTag("Player") == false) { return; } Debug.Log($"damaged player: {playerHealth.gameObject.name}"); playerHealth.Damage(_damage); _dealtDamage = true; StartCoroutine(Wait()); } }
void OnCollisionEnter2D(Collision2D collision) { // Collision with enemy EnemyScript enemy = collision.gameObject.GetComponent <EnemyScript>(); if (enemy != null) { // Kill the enemy HealthScript enemyHealth = enemy.GetComponent <HealthScript>(); if (enemyHealth != null) { enemyHealth.Damage(enemyHealth.hp); } HealthScript playerHealth = this.GetComponent <HealthScript>(); if (playerHealth != null) { playerHealth.Damage(1); } } }
IEnumerator Shoot() { audio_laser = GetComponent <AudioSource>(); audio_laser.Play(); RaycastHit2D hitInfo = Physics2D.Raycast(firePoint.position, firePoint.right); if (hitInfo) { Debug.Log(hitInfo.transform.name); EnemyScript enemy = hitInfo.transform.GetComponent <EnemyScript>(); ShotScript shot = hitInfo.transform.GetComponent <ShotScript>(); if (enemy != null) { HealthScript health = hitInfo.transform.GetComponent <HealthScript>(); if (health != null) { Debug.Log("DIE!!!!"); health.Damage(laserDmg); } } else if (shot != null) { Destroy(shot.gameObject); } lineRenderer.SetPosition(0, firePoint.position); lineRenderer.SetPosition(1, hitInfo.point); } else { Debug.Log("No Hit!"); lineRenderer.SetPosition(0, firePoint.position); lineRenderer.SetPosition(1, firePoint.position + firePoint.right * 100); } lineRenderer.enabled = true; yield return(new WaitForSeconds(0.02f)); lineRenderer.enabled = false; }
void Explode() { Destroy(GetComponent <SphereCollider>()); Collider[] colliders = Physics.OverlapSphere(transform.position, rocketRadius); float distance; float pushForce; float interpolant; foreach (Collider col in colliders) { distance = Vector3.Distance(col.transform.position, transform.position); interpolant = Mathf.Clamp01(Mathf.InverseLerp(0, rocketRadius, distance)); //Debug.Log("Distance: " + distance + "\nInterpolant: " + interpolant); Rigidbody hitRigidbody = col.gameObject.GetComponent <Rigidbody>(); if (hitRigidbody != null) { pushForce = Mathf.Lerp(rocketMaxStrength, 0, interpolant); // Debug.DrawLine(col.transform.position, transform.position, Color.cyan, 2f); // Debug.DrawRay(col.transform.position, Vector3.Normalize(col.transform.position - transform.position) * pushForce, Color.red, 2f); hitRigidbody.AddForce(Vector3.Normalize(col.transform.position - transform.position) * pushForce); } HealthScript healthScript = col.gameObject.GetComponent <HealthScript>(); if (healthScript != null) { healthScript.Damage(Mathf.Lerp(maxDamage, 0, interpolant)); } } if (!exploded) { GameObject effectGameObject = Instantiate(explosionEffect) as GameObject; effectGameObject.transform.localScale = new Vector3(rocketRadius * 2, rocketRadius * 2, rocketRadius * 2); effectGameObject.transform.position = this.transform.position; exploded = true; } StartCoroutine(ScheduleDestroy(0)); }
void Update() { if (Time.time > nextFire) { nextFire = Time.time + fireRate; // Store the timere of the last shot and use it in the if statement above for check if enogh time is pass. float angle = Quaternion.Angle(transform.rotation, Quaternion.LookRotation(target.transform.position - transform.position)); if (angle < FOW) { StartCoroutine(ShotEffect()); Vector3 rayOrigin = turretCamera.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0f)); // Center of the turret camera. RaycastHit hit; // Store the information if our ray hit a game object with an collider component attached. //Vector3 vector3 = new Vector3(0.0f, 0.4f, 0.0f); //Vector3 targetPosition = (projectileSpawn.position - vector3); rayLine.SetPosition(0, (projectileSpawn.position)); // Set the start position of the ray in the projectile spawn position. if (Physics.Raycast(rayOrigin, turretCamera.transform.forward, out hit, turretRange)) { rayLine.SetPosition(1, hit.point); HealthScript health = hit.collider.GetComponent <HealthScript>(); // Check if there is a HealthScript in the object hitted. if (health != null) { health.Damage(damage); // If the statement is true pass damage variable to health. } } else { rayLine.SetPosition(1, rayOrigin + (turretCamera.transform.forward * turretRange)); } } } }
void OnCollisionEnter2D(Collision2D collision) { bool damagePlayer = false; // Collision with enemy EnemyScript enemy = collision.gameObject.GetComponent <EnemyScript>(); if (enemy != null) { // Kill the enemy HealthScript enemyHealth = enemy.GetComponent <HealthScript>(); if (enemyHealth != null) { enemyHealth.Damage(enemyHealth.hp); } damagePlayer = true; } else { RedPoulpi redPoulpi = collision.gameObject.GetComponent <RedPoulpi>(); if (redPoulpi != null) { damagePlayer = true; } } // Damage the player if (damagePlayer) { HealthScript playerHealth = this.GetComponent <HealthScript>(); if (playerHealth != null) { playerHealth.Damage(1); } } }
private void OnCollisionEnter2D(Collision2D collision) { bool damagePlayer = false; // Collision with enemy EnemyScript enemy = collision.gameObject.GetComponent <EnemyScript>(); if (enemy != null) { // Kill the enemy HealthScript enemyHealth = enemy.GetComponent <HealthScript>(); if (enemyHealth != null) { enemyHealth.Damage(enemyHealth.hp); } damagePlayer = true; } ShrinkScript shrink = collision.gameObject.GetComponent <ShrinkScript>(); if (shrink != null) { hasPowerUp = true; powerupScript.GrantShrink(); Destroy(collision.gameObject); } // Damage the player if (damagePlayer) { HealthScript playerHealth = this.GetComponent <HealthScript>(); if (playerHealth != null) { playerHealth.Damage(1); } } }
void OnCollisionEnter2D(Collision2D collision) { bool damagePlayer = false; EnemyScript enemy = collision.gameObject.GetComponent <EnemyScript>(); if (enemy != null) { HealthScript enemyHealth = enemy.GetComponent <HealthScript>(); if (enemyHealth != null) { enemyHealth.Damage(enemyHealth.hp); } damagePlayer = true; } BossScript boss = collision.gameObject.GetComponent <BossScript>(); if (boss != null) { HealthScript bossHealth = boss.GetComponent <HealthScript>(); if (bossHealth != null) { bossHealth.Damage(5); } damagePlayer = true; } if (damagePlayer) { HealthScript playerHealth = this.GetComponent <HealthScript>(); if (playerHealth != null) { playerHealth.Damage(1); } } }
IEnumerator LaserShot(RaycastHit2D[] hits) { SpecialEffectsHelper.instance.Laser(this.transform.position); foreach (RaycastHit2D hit in hits) { HealthScript health = hit.transform.gameObject.GetComponent <HealthScript>(); // Avoid friendly fire if (health != null && health.isEnemy != this.isEnemyShot) { // Freeze them all for dramatic effect! MoveScript moveComponent = hit.transform.gameObject.GetComponent <MoveScript>(); if (moveComponent != null) { moveComponent.speed = new Vector3(0, 0, 0); } } } // Dramatic effect yield return(new WaitForSeconds(1)); foreach (RaycastHit2D hit in hits) { HealthScript health = hit.transform.gameObject.GetComponent <HealthScript>(); // Avoid friendly fire if (health != null && health.isEnemy != this.isEnemyShot) { Debug.Log("Laser hit! (" + health.transform.name + ")"); health.Damage(health.hp); // Kill } } yield return(null); }
void OnCollisionEnter2D(Collision2D collision) { /* 碰到对手 */ //Debug.Log ("OnCollisionEnter2D: " + collision.gameObject); mouseAudio.PlayOneShot(mousePong, 0.1f * collision.relativeVelocity.sqrMagnitude > 1f ? 1f : 0.1f * collision.relativeVelocity.sqrMagnitude); HealthScript hs = collision.gameObject.GetComponent <HealthScript>(); if (hs && hs.attack < attack) { // && hs.isEnemy != isEnemy) { // 攻击力不为0时,对对手和本方都会造成伤害 hs.Damage(attack - hs.attack); } // 碰到树桩受伤害 ItemScript iScript = collision.gameObject.GetComponent <ItemScript>(); if (iScript && iScript.isObstacle()) { Damage(iScript.damage); } }
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 OnCollisionEnter2D(Collision2D other) { // handle collisions with enemy EnemyScript enemy = other.gameObject.GetComponent <EnemyScript>(); if (enemy != null) { // destroy the enemy completely HealthScript enemy_health = enemy.GetComponent <HealthScript>(); if (enemy_health != null) { enemy_health.Damage(enemy_health.hp); } // but we also take 1 damage HealthScript my_health = GetComponent <HealthScript>(); if (my_health != null) { my_health.Damage(1); SoundEffectsHelper.instance.MakePlayerShotSound(); } } }
void OnCollisionEnter2D(Collision2D collision) { bool damagePlayer = false; EnemyScript enemy = collision.gameObject.GetComponent <EnemyScript> (); if (enemy != null) { HealthScript enemyHealth = enemy.GetComponent <HealthScript>(); if (enemyHealth != null) { enemyHealth.Damage(enemyHealth.hp); //completely kill the enemy player. } damagePlayer = true; } if (damagePlayer) { HealthScript playerHealth = this.GetComponent <HealthScript>(); if (playerHealth != null) { playerHealth.Damage(1); } } }
void OnCollisionEnter2D(Collision2D col) { if (col.gameObject.tag == "dead") { health.Damage(); rig.position = new Vector2(posX, posY); } if (col.gameObject.tag == "Heart") { health.incHealth(); Destroy(col.gameObject); } if (col.transform.tag == "MovingPlatform") { transform.parent = col.transform; } if (col.gameObject.tag == "LevelEnd") { Application.LoadLevel(Application.loadedLevel + 1); } }
void OnCollisionEnter2D(Collision2D collision) { bool damagePlayer = false; // Collision with enemy EnemyScript enemy = collision.gameObject.GetComponent <EnemyScript>(); if (invulnerable <= 0) { if (enemy != null) { Debug.LogWarning("Boom"); //Destroy(enemy.gameObject); //Kill the enemy HealthScript enemyHealth = enemy.GetComponent <HealthScript> (); if (enemyHealth != null && !enemy.isBoss) { enemyHealth.Damage(enemyHealth.hp); } damagePlayer = true; } // Damage the player if (damagePlayer) { invulnerable += iFrames; gameObject.collider2D.enabled = false; HealthScript playerHealth = this.GetComponent <HealthScript> (); if (playerHealth != null) { playerHealth.Damage(1); } } } }
void OnCollisionEnter2D(Collision2D collision) { int damagePlayer = 0; // Ignore collision when player is invincible Physics2D.IgnoreCollision(collision.gameObject.GetComponent <Collider2D>(), GetComponent <Collider2D>(), isInvincible); if (!isInvincible) { // Collision with enemy EnemyScript enemy = collision.gameObject.GetComponent <EnemyScript>(); if (enemy != null && collision.gameObject.GetComponent <BossScript>() == null) { // Kill the enemy HealthScript enemyHealth = enemy.GetComponent <HealthScript>(); if (enemyHealth != null) { damagePlayer = enemyHealth.hp / 3; if (shieldLevel + 1 >= damagePlayer) { enemyHealth.Damage(enemyHealth.hp); // kill enemy } } if (damagePlayer < 1) { damagePlayer = 1; } } } // Is this a bonus? CollectableScript collectable = collision.gameObject.GetComponentInChildren <CollectableScript>(); if (collectable != null) { // Is this a shield bonus? ShieldScript shield = collision.gameObject.GetComponent <ShieldScript>(); if (shield != null) { shieldLevel = shield.shieldLevel; lastShieldLevel = shieldLevel; updateShieldUi(); updateLifeUi(false); SoundEffectsHelper.Instance.MakeShieldSound(true); Destroy(shield.gameObject); // Remember to always target the game object, otherwise you will just remove the script } else { SoundEffectsHelper.Instance.MakePickupSound(); } // Is this a weapon bonus? changeWeapon(collision.gameObject); // Is this a bomb bonus? BombScript bomb = collision.gameObject.GetComponent <BombScript>(); if (bomb != null) { if (nbBombs < MAX_BOMB) { nbBombs++; GameHelper.Instance.pickupBomb(); } SoundEffectsHelper.Instance.MakePickupSound(); } GameHelper.Instance.collectBonus(collectable.getId()); Destroy(collision.gameObject); // Remember to always target the game object, otherwise you will just remove the script } // Damage the player if necessery if (this.takeDamage(damagePlayer)) { GetComponent <HealthScript>().Damage(1); } }
void OnCollisionEnter2D(Collision2D collision) { bool damagePlayer = false; // Collision with enemy EnemyScript enemy = collision.gameObject.GetComponent <EnemyScript>(); if (enemy) { // Kill the enemy HealthScript enemyHealth = enemy.GetComponent <HealthScript>(); if (enemyHealth) { enemyHealth.Damage(enemyHealth.hp); } //make explosion enemyHealth.ExplosionAnimation(explosionPrefab); SoundEffectsHelper.Instance.MakeDamageSound(); damagePlayer = true; } // Damage the player if (damagePlayer) { HealthScript playerHealth = GetComponent <HealthScript>(); if (playerHealth) { playerHealth.Damage(1); } } // Collision with area shot ammo AreaAmmoScript ammo = collision.gameObject.GetComponent <AreaAmmoScript>(); if (ammo) { AreaWeaponScript weapon = GetComponent <AreaWeaponScript>(); if (weapon) { weapon.ammunition += 1; ammoCounter.IncreaseCounter(); } Destroy(ammo.gameObject); } // Collision with time stop TimeStopScript timeStop = collision.gameObject.GetComponent <TimeStopScript>(); if (timeStop) { // disable box collider BoxCollider2D bc = timeStop.gameObject.GetComponent <BoxCollider2D>(); if (bc) { bc.enabled = false; } // disable renderer SpriteRenderer sr = timeStop.gameObject.GetComponent <SpriteRenderer>(); if (sr) { sr.enabled = false; } timeStop.StopTime(); } }
void OnCollisionEnter2D(Collision2D collision) { HealthScript playerHealth = GetComponent <HealthScript> (); OrangeCell orangeCell = collision.gameObject.GetComponent <OrangeCell>(); RedCell redCell = collision.gameObject.GetComponent <RedCell>(); BlueCell blueCell = collision.gameObject.GetComponent <BlueCell>(); NanitoControllerScript nanito = nanitoGO.GetComponent <NanitoControllerScript>(); if (collision.gameObject.tag == "orange") { if (nanito.shieldGO.activeSelf == true) { nanito.damagePlayer = false; nanito.shieldHits--; Debug.Log("shield hit"); //orangeCell = null; if (playerHealth != null) { playerHealth.Damage(orangeCell.damage, nanito.respawnPosX, nanito.respawnPosY, true); } } else { nanito.damagePlayer = true; Debug.Log("shield not hit"); if (playerHealth != null) { playerHealth.Damage(orangeCell.damage, nanito.respawnPosX, nanito.respawnPosY, false); } } } if (collision.gameObject.tag == "red") { if (nanito.shieldGO.activeSelf == true) { nanito.damagePlayer = false; nanito.shieldHits--; Debug.Log("shield hit"); //orangeCell = null; } else { nanito.damagePlayer = true; Debug.Log("shield not hit"); if (playerHealth != null) { playerHealth.Damage(redCell.damage, nanito.respawnPosX, nanito.respawnPosY, false); } } } if (collision.gameObject.tag == "blue") { if (nanito.shieldGO.activeSelf == true) { nanito.damagePlayer = false; nanito.shieldHits--; Debug.Log("shield hit"); //orangeCell = null; } else { nanito.damagePlayer = true; Debug.Log("shield not hit"); if (playerHealth != null) { playerHealth.Damage(blueCell.damage, nanito.respawnPosX, nanito.respawnPosY, false); } } } }