Advertisement
Aaron_ggf

health and attack not working

May 26th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. // Player Health
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using UnityEngine.SceneManagement;
  7.  
  8. //Aaron barker, Jake Acworth
  9. public class PlayerHealth : MonoBehaviour
  10. {
  11.  
  12. [SerializeField] private GameObject deathCanvas;
  13. int damage = 1;
  14. public GameObject[] health_Count = new GameObject[3];
  15. int maxHealth = 3;
  16. public Transform Player;
  17. //public PauseGame menu;
  18.  
  19.  
  20. private void Start()
  21. {
  22. deathCanvas.SetActive(false);
  23. //ealth_Count.maxValue = maxHealth;
  24. //Health_Count.value = maxHealth;
  25. damage = 1;
  26. }
  27.  
  28. private void Update()
  29. {
  30. if (maxHealth == 0)
  31. {
  32. Die ();
  33. }
  34. }
  35. private void OnTriggerEnter(Collider other)
  36. {
  37. if (other.transform.tag == "Enemy")
  38. {
  39. Debug.Log("ouch");
  40. AttackPlayer();
  41. }
  42. }
  43.  
  44. void Changelevel(string leveltoload)
  45. {
  46. // SceneManager.LoadScene("endDeath");
  47. }
  48. private void Die()
  49. {
  50. //SceneManager.LoadScene ("EndDeath");
  51. Time.timeScale = 0.0f;
  52. //deathCanvas.SetActive(true);
  53. Cursor.visible = true;
  54. Cursor.lockState = CursorLockMode.None;
  55. Player.GetComponent<TileMovement>().enabled = false;
  56. //menu.GetComponent<PauseMenu>().enabled = false;
  57. }
  58.  
  59. public void AttackPlayer()
  60. {
  61. maxHealth -= damage;
  62. DestroyObject(health_Count[maxHealth]);
  63. }
  64. }
  65. //Player Health
  66. ////////////////// Two different Scripts
  67. //Enemy Attack
  68. using System.Collections;
  69. using System.Collections.Generic;
  70. using UnityEngine;
  71.  
  72. public class EnemyAttack : MonoBehaviour
  73. {
  74.  
  75. public float Damage = 0.2f;
  76. public PlayerHealth playerhealth;
  77. public void Start()
  78. {
  79. playerhealth = GetComponent<PlayerHealth>();
  80. }
  81. private void OnTriggerEnter(Collider collision)
  82. {
  83.  
  84. if (collision.gameObject.tag == "Player")
  85. {
  86. Debug.Log("This collider got hit");
  87. playerhealth.AttackPlayer();
  88. }
  89. }
  90. }
  91. //Enemy Attack
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement