public void MinusHealth(int health) { enemy.currHealth -= health; if (enemy.currHealth == 2) { // GameObject particleRadius = transform.Find("particleRadius").gameObject; enemyRadius = particleRadius.GetComponent <EnemyRadius>(); enemyPlayerInteraction.DamageFeedback(); // player enemyRadius.circleParticlesTwo.Stop(); enemyRadius.circleParticlesTwo.gameObject.SetActive(false); } if (enemy.currHealth == 1) { // GameObject particleRadius = transform.Find("particleRadius").gameObject; enemyRadius = particleRadius.GetComponent <EnemyRadius>(); enemyPlayerInteraction.DamageFeedback(); enemyRadius.circleParticlesOne.Stop(); enemyRadius.circleParticlesOne.gameObject.SetActive(false); } if (enemy.currHealth <= 0) { // Debug.Log(enemy.currHealth); enemyDeath.Kill(); // Debug.Log("urp"); // Transform enemyChild = transform.Find("enemy mit joints"); foreach (Transform gc in enemyChild) { if (gc.name == "Enemy") { GameObject enemyGrandchild = gc.gameObject; enemyDissolve = enemyGrandchild.GetComponent <EnemyDissolve>(); enemyDissolve.dissolveNow(); } } } /* * else * { * * StartCoroutine(MinusHealthCoroutine()); * * } */ }
//Remove an enemy (EnemyRadius) from the enemyList. //Called from the OnDestroy function when an enemy is destroyed. public static void DestroyEnemy(EnemyRadius enemy) { for (int i = 0; i < enemyList.Count; i++) { if (enemyList[i] == enemy) { enemyList.RemoveAt(i); break; } } }
void Start() { origin = transform.position; enemiesRender = transform.GetChild(1).GetChild(0).GetComponent <SpriteRenderer>(); rg = transform.GetComponent <Rigidbody2D>(); _objPlayer = GameObject.Find("PlayerTest").gameObject; _player = _objPlayer.GetComponent <PlayerController>(); movementSpeed = 50.0f; maxDistance = 6f; //Changes certain basic variables depending on basic behavior type. switch (basicBehavior) { case BasicBehavior.LeftRight: horiAxes = 1f; vertAxis = 0f; break; case BasicBehavior.TopDown: horiAxes = 0f; vertAxis = 1f; ignoreHoles = true; _gaz = new AB_Gaz(this); break; case BasicBehavior.WaveLR: horiAxes = 1f; vertAxis = 0f; ignoreHoles = true; break; case BasicBehavior.Motionless: horiAxes = 0f; vertAxis = 0f; break; default: horiAxes = 1f; vertAxis = 0f; break; } //Initialise the list of Advanced Behaviors according to the ones chosen in inspector. if (abList.Length > 0) { for (int i = 0; i < abList.Length; i++) { if (abList[i]) { advancedBehaviors.Add(new AB_RadiusBased(this, movementSpeed)); float radius; EnemyRadius enemyRadius = transform.GetChild(0).GetChild(1).GetComponent <EnemyRadius>(); if (enemyRadius == null) { Debug.Log("Error getting enemy's radius."); } else { radius = enemyRadius.radius * 2; if (i == 0) { (advancedBehaviors[advancedBehaviors.Count - 1] as AB_RadiusBased).SetValues(0, radius, false); //stickToWalls = true; } else if (i == 1) { (advancedBehaviors[advancedBehaviors.Count - 1] as AB_RadiusBased).SetValues(1, radius, false); } else if (i == 2) { (advancedBehaviors[advancedBehaviors.Count - 1] as AB_RadiusBased).SetValues(2, radius, false); } else if (i == 3) { (advancedBehaviors[advancedBehaviors.Count - 1] as AB_RadiusBased).SetValues(3, radius, false); } } } } } }
//Returns the distance between an enemy and the hero. private static float GetDistanceFromEnemy(EnemyRadius enemy, Vector2 heroPosition) { return(new Vector2(enemy.transform.position.x - heroPosition.x, enemy.transform.position.y - heroPosition.y).magnitude); }
//Add an enemy (EnemyRadius) to the enemyList. //Called from the Start function of all enemies. public static void AddEnemy(EnemyRadius enemy) { enemyList.Add(enemy); }