Newer
Older
TheVengeance-Project-IADE-Unity2D / Assets / Scripts / NPC / Boss Sime / Bullet.cs
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Bullet : MonoBehaviour
  5. {
  6. //Files
  7. private PlayerLife playerLife;
  8. private PlayerController playerController;
  9. //Floats
  10. public float bulletlifeTime = 2;
  11. //Ints
  12. public int rangedBossSlimeAttack = 15;
  13. void Start()
  14. {
  15. Destroy(gameObject, bulletlifeTime);
  16. playerLife = FindObjectOfType<PlayerLife>(); // to access the Player Level file
  17. playerController = FindObjectOfType<PlayerController>(); // to access the Player Attack and Block file
  18. }
  19. private void OnCollisionEnter2D(Collision2D collision)
  20. {
  21. if (collision.gameObject.tag == "Player")
  22. {
  23. playerController.flashActive = true;
  24. playerController.flashCounter = playerController.flashLength;
  25. if (playerController.shield == true && rangedBossSlimeAttack > playerController.defensePlayer) //if player is blocking but the attack value is bigger than the defense value
  26. {
  27. playerLife.life -= rangedBossSlimeAttack - playerController.defensePlayer;
  28. }
  29. else if (playerController.shield == false) //if player isn't blocking
  30. {
  31. playerLife.life -= rangedBossSlimeAttack;
  32. }
  33. Destroy(gameObject);
  34. }
  35. }
  36. }