- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerBullet : MonoBehaviour
- {
- private Transform player;
- [SerializeField]
- private float damage;
- [SerializeField]
- private float attackRange;
- void Start()
- {
-
- player = GameObject.FindGameObjectWithTag("Player").transform;
- }
-
- void Update()
- {
- if (Vector3.Distance(player.position, transform.position) > attackRange) Destroy(gameObject);
- }
-
- private void OnCollisionEnter(Collision collision)
- {
-
- if (collision.transform.CompareTag("Enemy"))
- {
- collision.transform.GetComponent<Health>().LooseHp(damage, transform.forward);
- }
- }
- }