Skip to content
Permalink
d864e80fc3
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
85 lines (62 sloc) 1.72 KB
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Enemy1 : 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("BeeHit");
if (currentHealth <= 0)
{
Instantiate(score, new Vector3(ghost.position.x, ghost.position.y, ghost.position.z), Quaternion.identity);
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("BeeHit");
}
}
float CalculateHealth()
{
return currentHealth / maxHealth;
}
}