fgm24/Assets/Scripts/Controller/RumbleManager.cs

37 lines
878 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class RumbleManager : MonoBehaviour
{
private Gamepad pad1;
private Gamepad pad2;
private Coroutine stopRumbleAfterTimeCorutine;
public void RumblePulse(float lowFrequency, float highFrequency, float duration, int player)
{
pad1 = Gamepad.all[0];
if (pad1 != null)
{
pad1.SetMotorSpeeds(lowFrequency, highFrequency);
stopRumbleAfterTimeCorutine = StartCoroutine(stopRumble(duration, pad1));
}
}
private IEnumerator stopRumble(float duration, Gamepad pad)
{
float elapsedTime = 0f;
while (elapsedTime < duration)
{
elapsedTime += Time.deltaTime;
yield return null;
}
pad.SetMotorSpeeds(0f, 0f);
}
}