2024-02-02 22:43:39 +01:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.InputSystem;
|
|
|
|
|
|
|
|
public class RumbleManager : MonoBehaviour
|
|
|
|
{
|
2024-02-03 15:45:11 +01:00
|
|
|
private Gamepad pad;
|
2024-02-02 22:43:39 +01:00
|
|
|
|
|
|
|
private Coroutine stopRumbleAfterTimeCorutine;
|
|
|
|
|
|
|
|
|
2024-02-03 15:21:45 +01:00
|
|
|
public void RumblePulse(float lowFrequency, float highFrequency, float duration, int player)
|
2024-02-02 22:43:39 +01:00
|
|
|
{
|
2024-02-03 15:45:11 +01:00
|
|
|
pad = Gamepad.all[player];
|
|
|
|
if (pad != null)
|
2024-02-02 22:43:39 +01:00
|
|
|
{
|
2024-02-03 15:45:11 +01:00
|
|
|
pad.SetMotorSpeeds(lowFrequency, highFrequency);
|
2024-02-02 22:43:39 +01:00
|
|
|
|
2024-02-03 15:45:11 +01:00
|
|
|
stopRumbleAfterTimeCorutine = StartCoroutine(stopRumble(duration, pad));
|
2024-02-02 22:43:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerator stopRumble(float duration, Gamepad pad)
|
|
|
|
{
|
|
|
|
float elapsedTime = 0f;
|
|
|
|
while (elapsedTime < duration)
|
|
|
|
{
|
|
|
|
elapsedTime += Time.deltaTime;
|
|
|
|
yield return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
pad.SetMotorSpeeds(0f, 0f);
|
|
|
|
}
|
|
|
|
}
|