Newer
Older
HardPoint-Project-Abertay-University-Unity3D / Assets / Scripts / CharacterClasses / MercenaryBullet.cs
@Rackday Rackday on 18 Aug 1008 bytes Project Added
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MercenaryBullet : MonoBehaviour
{
    [SerializeField] private float bulletLife;
    [SerializeField] private float maxDamage;
    [SerializeField] private float currentDamage;
    [SerializeField] private float damageRate;

    // Start is called before the first frame update
    void Start()
    {
        currentDamage = maxDamage;
        Destroy(gameObject, bulletLife);
    }

    void OnCollisionEnter(Collision collision)
    {
        HealthSystem temp = collision.gameObject.GetComponent<HealthSystem>();
        if (temp != null)
            temp.TakeDamage(currentDamage, gameObject);
  
        Destroy(gameObject);
    }

        // Update is called once per frame
    void Update()
    {
        currentDamage -= damageRate * Time.deltaTime;

        if (currentDamage > 0f)
            currentDamage -= damageRate * Time.deltaTime;

        //Debug.Log("current damage: " + currentDamage);
    }
}