Skip to content
Permalink
4d38e1d4d3
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
87 lines (64 sloc) 1.81 KB
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;
}
}