Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Platformer/Platformer/Assets/Bee_Enemy.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
87 lines (64 sloc)
1.81 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.UI; | |
public class Bee_Enemy : MonoBehaviour | |
{ | |
public Animator animator; | |
public float maxHealth = 75; //health | |
public float currentHealth; | |
public GameObject healthBarUI; | |
public Slider slider; | |
public GameObject enemie; | |
public Transform ghost; | |
public int Shurikendamage = 10; | |
public GameObject score; //shuriken | |
void Start() | |
{ | |
currentHealth = maxHealth; | |
slider.value = CalculateHealth(); | |
ghost.position = new Vector3(ghost.position.x, ghost.position.y, ghost.position.z); | |
} | |
void Update() | |
{ | |
slider.value = CalculateHealth(); | |
if (currentHealth < maxHealth) | |
{ | |
healthBarUI.SetActive(true); | |
} | |
} | |
public void TakeDamage(int damage) | |
{ | |
healthBarUI.SetActive(true); | |
currentHealth -= damage; | |
slider.value = CalculateHealth(); | |
//Hurt Animation | |
SoundManagerScript.PlaySound("GhostHurt"); | |
animator.SetTrigger("Hurt"); | |
if (currentHealth <= 0) | |
{ | |
Instantiate(score, new Vector3(ghost.position.x, ghost.position.y, ghost.position.z), Quaternion.identity); | |
animator.SetBool("IsDead", true); | |
Die(); | |
} | |
} | |
void Die() | |
{ | |
enemie.SetActive(false); | |
} | |
private void OnTriggerEnter2D(Collider2D other) | |
{ | |
if (other.gameObject.CompareTag("Bullet")) | |
{ | |
other.gameObject.SetActive(false); | |
TakeDamage(Shurikendamage); | |
healthBarUI.SetActive(true); | |
slider.value = CalculateHealth(); | |
SoundManagerScript.PlaySound("GhostHurt"); | |
} | |
} | |
float CalculateHealth() | |
{ | |
return currentHealth / maxHealth; | |
} | |
} |