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