34 lines
1.0 KiB
C#
34 lines
1.0 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
public class Projectile : MonoBehaviour
|
||
{
|
||
[SerializeField] private float damage;
|
||
|
||
private bool haveBeenReflected = false;
|
||
public void Init(float speed)
|
||
{
|
||
GetComponent<Rigidbody2D>().velocity = transform.up * speed;
|
||
}
|
||
|
||
private void OnCollisionEnter2D(Collision2D collision)
|
||
{
|
||
// Hvad fuck er det her kode <20>rligt. hj<68>lp
|
||
{
|
||
if (haveBeenReflected && collision.gameObject.CompareTag("Enemy"))
|
||
{
|
||
HealthComponent enemyHealth = collision.gameObject.GetComponent<HealthComponent>();
|
||
enemyHealth.TakeDamage(damage);
|
||
Destroy(gameObject);
|
||
}
|
||
else if (collision.gameObject.CompareTag("Player"))
|
||
{
|
||
HealthComponent playerHealth = collision.gameObject.GetComponent<HealthComponent>();
|
||
playerHealth.TakeDamage(damage);
|
||
Destroy(gameObject);
|
||
}
|
||
}
|
||
}
|
||
}
|