コード例 #1
0
ファイル: Enemy.cs プロジェクト: PanosKikas/Monser-s-Lair
	static int sortingOrder = 100; // It's order in the particular sortingLayer

	void Start () 
	{
		health = startHealth;
		enemyMovement = GetComponent<Pathfinding>();
		healthIndicator = GetComponentInChildren<HealthIndicator>();
		++WaveSpawner.enemiesAlive; 
		healthIndicator.UpdateStatus((int)health, startHealth); // Update the values of the healthbar
		animator = GetComponent<Animator>();
		isDead = false;
		speed = startSpeed;
		sr = GetComponentInChildren<SpriteRenderer>();
		startColor = sr.color;
		sr.sortingOrder = sortingOrder;
		--sortingOrder; // Decrements the sorting order so that the next enemy to be spawned is gonna appear besides him
	}
コード例 #2
0
ファイル: Enemy.cs プロジェクト: PanosKikas/Monser-s-Lair
	// Function that damages the current enemy
	 IEnumerator TakeDamageCo(float damage)
	{
		if (isDead)
			yield return null;

		health -= damage; // Decrement its health
		
		healthIndicator.UpdateStatus(Mathf.CeilToInt(health), startHealth); 
		sr.color = flashColor; 
		yield return new WaitForSeconds(0.1f);
		
		sr.color = startColor;
		// Check if it died
		if (health <= 0 && !isDead)
		{
			Die();
		}
	}