Danro/Assets/Resources/Scripts/BasicProjectile.cs

43 lines
1.2 KiB
C#

using Projectiles2D;
using UnityEngine;
public class BasicProjectile : Projectile2D
{
[Header("FX")]
[SerializeField] private GameObject hitVfxPrefab;
[SerializeField] private AudioClip hitSfx;
[SerializeField] private float sfxVolume = 1f;
protected override void OnHit(Collider2D target, Vector2 point, Vector2 relativeVelocity)
{
//var health = target.GetComponentInParent<Health>();
//if (health != null)
//{
// health.ApplyDamage(damage);
// if (knockback > 0f)
// {
// var targetRb = target.attachedRigidbody;
// if (targetRb != null)
// {
// var dir = relativeVelocity.sqrMagnitude > 0.0001f
// ? relativeVelocity.normalized
// : (Vector2)(target.transform.position - transform.position).normalized;
// targetRb.AddForce(dir * knockback, ForceMode2D.Impulse);
// }
// }
//}
if (hitVfxPrefab != null)
{
Instantiate(hitVfxPrefab, point, Quaternion.identity);
}
if (hitSfx != null)
{
AudioSource.PlayClipAtPoint(hitSfx, point, sfxVolume);
}
}
}