Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. IT'S Health script
  2.  
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6.  
  7. public class Healthship : MonoBehaviour
  8. {
  9. public int maxhealth = 100;
  10. public int health;
  11.  
  12.  
  13. void Start()
  14. {
  15. health = maxhealth;
  16. }
  17.  
  18.  
  19. void FixUpdate()
  20. {
  21. maxhealth = health;
  22. if (health < 0)
  23. { health = 0; }
  24. if (health <= 0)
  25. { Destroy(gameObject); }
  26.  
  27. }
  28. void Update()
  29. {
  30. Debug.Log(health);
  31. }
  32. }
  33.  
  34.  
  35.  
  36.  
  37. IT'S Damage script
  38.  
  39.  
  40. using System.Collections;
  41. using System.Collections.Generic;
  42. using UnityEngine;
  43.  
  44. public class damage : MonoBehaviour
  45. {
  46. public Healthship hp;
  47. public int damag = 10;
  48. void Start()
  49. {
  50.  
  51. }
  52. void OnCollisionEnter(Collision col)
  53. {
  54.  
  55. if (col.gameObject.tag == "Ship")
  56. {
  57. hp.health -= damag;
  58.  
  59. }
  60. if (hp.health <= 0)
  61. {
  62. Destroy(gameObject);
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement