Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / Scripts / Bullet.cs
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Bullet : MonoBehaviour
  5. {
  6. Rigidbody rb;
  7. float timer = 5;
  8. private void Start()
  9. {
  10. rb = GetComponent<Rigidbody>();
  11. }
  12. private void Update()
  13. {
  14. timer -= Time.deltaTime;
  15. if (timer <= 0) Destroy(gameObject);
  16. }
  17. private void OnCollisionEnter(Collision collision)
  18. {
  19. if (collision.gameObject.CompareTag("Player") || collision.gameObject.CompareTag("Enemy"))
  20. {
  21. Health hp = collision.gameObject.GetComponent<Health>();
  22. if (!hp.parry)
  23. {
  24. Debug.Log("Didn't Parry");
  25. hp.LooseHp(10, transform.forward);
  26. Destroy(gameObject);
  27. }
  28. else
  29. {
  30. Debug.Log("Parry");
  31. rb.velocity = collision.transform.forward * rb.velocity.magnitude;
  32. }
  33. }
  34. else
  35. Destroy(gameObject);
  36. }
  37. }