Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Player Health
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- //Aaron barker, Jake Acworth
- public class PlayerHealth : MonoBehaviour
- {
- [SerializeField] private GameObject deathCanvas;
- int damage = 1;
- public GameObject[] health_Count = new GameObject[3];
- int maxHealth = 3;
- public Transform Player;
- //public PauseGame menu;
- private void Start()
- {
- deathCanvas.SetActive(false);
- //ealth_Count.maxValue = maxHealth;
- //Health_Count.value = maxHealth;
- damage = 1;
- }
- private void Update()
- {
- if (maxHealth == 0)
- {
- Die ();
- }
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.transform.tag == "Enemy")
- {
- Debug.Log("ouch");
- AttackPlayer();
- }
- }
- void Changelevel(string leveltoload)
- {
- // SceneManager.LoadScene("endDeath");
- }
- private void Die()
- {
- //SceneManager.LoadScene ("EndDeath");
- Time.timeScale = 0.0f;
- //deathCanvas.SetActive(true);
- Cursor.visible = true;
- Cursor.lockState = CursorLockMode.None;
- Player.GetComponent<TileMovement>().enabled = false;
- //menu.GetComponent<PauseMenu>().enabled = false;
- }
- public void AttackPlayer()
- {
- maxHealth -= damage;
- DestroyObject(health_Count[maxHealth]);
- }
- }
- //Player Health
- ////////////////// Two different Scripts
- //Enemy Attack
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class EnemyAttack : MonoBehaviour
- {
- public float Damage = 0.2f;
- public PlayerHealth playerhealth;
- public void Start()
- {
- playerhealth = GetComponent<PlayerHealth>();
- }
- private void OnTriggerEnter(Collider collision)
- {
- if (collision.gameObject.tag == "Player")
- {
- Debug.Log("This collider got hit");
- playerhealth.AttackPlayer();
- }
- }
- }
- //Enemy Attack
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement