Skip to content
Snippets Groups Projects
Commit 973f12cc authored by Mitchel Kovacs's avatar Mitchel Kovacs
Browse files

changed scripts so health bar is changed and player can take damage

parent 8a2e1087
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,9 @@ public class ArenaCombatControl : MonoBehaviour {
private Rigidbody2D Player;
private Animator myAnimator;
public static float health;
EnterDoor spawn;
public float original;
[SerializeField]
private float speed;
private bool LookRight = true;
......@@ -20,6 +22,8 @@ public class ArenaCombatControl : MonoBehaviour {
// Use this for initialization
void Start() {
health = 50;
original = health;
//weapons[currentWeapon].attackSpeed = 1f;
Player = GetComponent<Rigidbody2D>();
myAnimator = GetComponent<Animator>(); //required for animation *******
......@@ -128,6 +132,31 @@ public class ArenaCombatControl : MonoBehaviour {
canJump = true;
}
}
IEnumerator waitandload()
{
yield return new WaitForSeconds(2.0f);
SceneManager.LoadScene("mainmenu");
}
public void ApplyDamageP(int damage)
{
health -= damage;
if (health <= 0)
{
StartCoroutine("waitandload");
}
}
public void ChangeHealthBarp(int damage)
{
GameObject healthbar = GameObject.Find("healthbarFullp");
float newsize = healthbar.transform.localScale.x - ((damage / original) * 0.3f);
healthbar.transform.localScale = new Vector3(newsize,0.3f,1f);
if(health <= 0)
{
healthbar.GetComponent<SpriteRenderer>().enabled = false;
}
}
/* can change stats simply in the inspector for dynamic purposes :)
//a few proposed weapon stats
......
......@@ -7,8 +7,8 @@ public class EnemyAI : MonoBehaviour {
private Transform target;
private Rigidbody2D Enemy;
private Animator myAnimator;
private float enemyHealth;
private float playerHealth;
public float enemyHealth, original;
float playerHealth;
private bool LookRight = false;
public bool set;
private float speed = 1;
......@@ -16,11 +16,13 @@ public class EnemyAI : MonoBehaviour {
void Start() {
enemyHealth = EnemyHealth.health;
playerHealth = PlayerStats.getHealth();
enemyHealth = Random.Range(50, 500);
original = enemyHealth;
playerHealth = ArenaCombatControl.health;
root = new DecisionTree();
// Debug.Log("start");
target = GameObject.FindGameObjectWithTag("Player").transform; //look at the player
myAnimator = GetComponent<Animator>(); //required for animation *******
Enemy = GetComponent<Rigidbody2D>();
......@@ -34,7 +36,25 @@ public class EnemyAI : MonoBehaviour {
root.search();
}
public void ChangeHealthBare(int damage)
{
GameObject healthbar = GameObject.Find("healthbarFulle");
float newsize = healthbar.transform.localScale.x - ((damage / original)*0.3f);
healthbar.transform.localScale = new Vector3(newsize, 0.3f, 1f);
if (enemyHealth <= 0)
{
healthbar.GetComponent<SpriteRenderer>().enabled = false;
}
}
public void ApplyDamageE(int damage)
{
enemyHealth -= damage;
if (enemyHealth <= 0)
{
Destroy(gameObject);
}
}
public bool d_inAttackRange() {
if (Vector3.Distance(transform.position, target.position) < 1.5f) {
......
using UnityEngine;
using System.Collections;
public class EnemyHealth : MonoBehaviour {
public class EnemyAttack : MonoBehaviour {
/*SCRIPT FOR WHEN THE PLAYER IS HIT, NOT THE ENEMY*/
public static float health;
void Start() {
health = Random.Range(50, 500);
}
// Update is called once per frame
void Update() {
if (health <= 0) {
Destroy(gameObject);
}
void Start()
{
GameObject weapon = GameObject.Find("weapon");
Physics2D.IgnoreCollision(weapon.GetComponent<Collider2D>(), GetComponent<Collider2D>());
}
//allow the player to only be hurt by the enemy
void OnTriggerEnter2D(Collider2D other) {
if (other.gameObject.tag == "Enemy") {
//apply damage if the collision is the player
void OnCollisionEnter2D(Collision2D other) {
if (other.gameObject.name == "Player") {
Debug.Log("hit");
health = health - 1;
other.gameObject.SendMessage("ApplyDamageP", 1, SendMessageOptions.DontRequireReceiver);
other.gameObject.SendMessage("ChangeHealthBarp", 1, SendMessageOptions.DontRequireReceiver);
}
}
......
fileFormatVersion: 2
guid: 6c3c5e21234caa3468025629dfa57435
timeCreated: 1478731483
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment