bullet bounce sfx

This commit is contained in:
Sveske Juice 2024-04-21 03:22:20 +02:00
parent 23d2a439c4
commit 99bc1cac0c
1 changed files with 5 additions and 0 deletions

View File

@ -1,5 +1,6 @@
using UnityEngine; using UnityEngine;
using UnityEngine.Assertions; using UnityEngine.Assertions;
using UnityEngine.Events;
[RequireComponent(typeof(Collider))] [RequireComponent(typeof(Collider))]
public class Projectile : MonoBehaviour public class Projectile : MonoBehaviour
@ -19,6 +20,8 @@ public class Projectile : MonoBehaviour
public HealthComponent comingFrom; public HealthComponent comingFrom;
public UnityEvent OnReflect;
private Vector3 prevVel; private Vector3 prevVel;
private void Awake() private void Awake()
@ -59,6 +62,8 @@ public class Projectile : MonoBehaviour
} }
Vector3 newVel = Vector3.Reflect(prevVel.normalized, collision.contacts[0].normal.normalized); Vector3 newVel = Vector3.Reflect(prevVel.normalized, collision.contacts[0].normal.normalized);
body.velocity = newVel.normalized * prevVel.magnitude * bounciness; body.velocity = newVel.normalized * prevVel.magnitude * bounciness;
OnReflect?.Invoke();
AudioManager.PlaySound("BulletBounce", transform.position);
} }
} }
} }