Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / Scripts / Bullet.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bullet : MonoBehaviour
{
    Rigidbody rb;
    float timer = 5;
    private void Start()
    {
        rb = GetComponent<Rigidbody>();
    }
    private void Update()
    {
        timer -= Time.deltaTime;
        if (timer <= 0) Destroy(gameObject);
    }
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag("Player") || collision.gameObject.CompareTag("Enemy"))
        {
            Health hp = collision.gameObject.GetComponent<Health>();
            if (!hp.parry)
            {
                Debug.Log("Didn't Parry");
                hp.LooseHp(10, transform.forward);
                Destroy(gameObject);
            }
            else
            {
                Debug.Log("Parry");
                rb.velocity = collision.transform.forward * rb.velocity.magnitude;
            }
            
        }
        else
        Destroy(gameObject);
        
        
    }
}