Skip to content
Permalink
07bb02fdb8
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
127 lines (100 sloc) 3.51 KB
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Boss : 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 GameObject score; //shuriken
public GameObject key; //drop key
public int Shurikendamage = 10;
public Transform player;
public bool isFlipped = false;
//Same as other scripts
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);
}
}
//this way the sprite is alwyas facing the correct direction
public void LookAtPlayer()
{
//ysed local scale
Vector3 flipped = transform.localScale;
flipped.z *= -1f;
if (transform.position.x > player.position.x && isFlipped)
{
//not flipped
transform.localScale = flipped;
transform.Rotate(0f, 180f, 0f);
isFlipped = false;
}
else if (transform.position.x < player.position.x && !isFlipped)
{
//flipped
transform.localScale = flipped;
transform.Rotate(0f, 180f, 0f);
isFlipped = true;
}
}
public void TakeDamage(int damage)
{
healthBarUI.SetActive(true);
currentHealth -= damage;
slider.value = CalculateHealth();
//Hurt Animation
SoundManagerScript.PlaySound("KnightHurt");
if (currentHealth < 50)
{
GetComponent<Animator>().SetBool("IsEnraged", true);
}
if (currentHealth <= 0)
{
//drop score and key
Instantiate(key, new Vector3(ghost.position.x, ghost.position.y, ghost.position.z), Quaternion.identity);
Instantiate(score, new Vector3(ghost.position.x, ghost.position.y, ghost.position.z), Quaternion.identity);
Instantiate(score, new Vector3(ghost.position.x, ghost.position.y, ghost.position.z), Quaternion.identity);
Instantiate(score, new Vector3(ghost.position.x, ghost.position.y, ghost.position.z), Quaternion.identity);
Instantiate(score, new Vector3(ghost.position.x, ghost.position.y, ghost.position.z), Quaternion.identity);
Instantiate(score, new Vector3(ghost.position.x, ghost.position.y, ghost.position.z), Quaternion.identity);
Instantiate(score, new Vector3(ghost.position.x, ghost.position.y, ghost.position.z), Quaternion.identity);
Instantiate(score, new Vector3(ghost.position.x, ghost.position.y, ghost.position.z), Quaternion.identity);
Die();
}
}
void Die()
{
enemie.SetActive(false);
}
//if hi tby bullet
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Bullet"))
{
other.gameObject.SetActive(false);
TakeDamage(Shurikendamage);
healthBarUI.SetActive(true);
slider.value = CalculateHealth();
SoundManagerScript.PlaySound("KnightHurt");
}
}
float CalculateHealth()
{
return currentHealth / maxHealth;
}
}