38 lines
1.0 KiB
C#
38 lines
1.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
public class ObjectImpactEvent : MonoBehaviour
|
|
{
|
|
[SerializeField] private UnityEvent eventAfterObjectImpact;
|
|
[SerializeField] private LayerMask collisionLayer;
|
|
|
|
public bool DoOnce;
|
|
private bool DidOnce;
|
|
|
|
private void OnCollisionEnter(Collision collision)
|
|
{
|
|
// Check if the collision is with an object on the collisionLayer.
|
|
if (!DidOnce)
|
|
{
|
|
if (collisionLayer == (collisionLayer | (1 << collision.gameObject.layer)))
|
|
{
|
|
eventAfterObjectImpact.Invoke();
|
|
StartCoroutine(ControllerRumbleImpact());
|
|
if (DoOnce)
|
|
{
|
|
DidOnce = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
IEnumerator ControllerRumbleImpact()
|
|
{
|
|
RumbleManager.GetInstance().StartRumble(0.4f, 0.4f);
|
|
yield return new WaitForSeconds(0.5f);
|
|
RumbleManager.GetInstance().StopRumble();
|
|
}
|
|
}
|