Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / PlayerBullet.cs
@Rackday Rackday on 21 Aug 806 bytes Project Added
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;
    }

    // Update is called once per frame
    void Update()
    {
        if (Vector3.Distance(player.position, transform.position) > attackRange) Destroy(gameObject);
    }

    
    private void OnCollisionEnter(Collision collision)
    {
        //Debug.Log("Collided");
        if (collision.transform.CompareTag("Enemy"))
        {
            collision.transform.GetComponent<Health>().LooseHp(damage, transform.forward);
        }
    }
}