Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / PlayerBullet.cs
@Rackday Rackday on 21 Aug 2024 806 bytes Project Added
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class PlayerBullet : MonoBehaviour
  5. {
  6. private Transform player;
  7. [SerializeField]
  8. private float damage;
  9. [SerializeField]
  10. private float attackRange;
  11. void Start()
  12. {
  13. player = GameObject.FindGameObjectWithTag("Player").transform;
  14. }
  15. // Update is called once per frame
  16. void Update()
  17. {
  18. if (Vector3.Distance(player.position, transform.position) > attackRange) Destroy(gameObject);
  19. }
  20. private void OnCollisionEnter(Collision collision)
  21. {
  22. //Debug.Log("Collided");
  23. if (collision.transform.CompareTag("Enemy"))
  24. {
  25. collision.transform.GetComponent<Health>().LooseHp(damage, transform.forward);
  26. }
  27. }
  28. }