fgm24/Assets/Scripts/Controller/RumbleManager.cs

47 lines
1.2 KiB
C#
Raw Normal View History

2024-02-02 22:43:39 +01:00
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 RumblePulse1(float lowFrequency, float highFrequency, float duration)
{
pad1 = Gamepad.all[0];
if (pad1 != null)
{
pad1.SetMotorSpeeds(lowFrequency, highFrequency);
stopRumbleAfterTimeCorutine = StartCoroutine(stopRumble(duration, pad1));
}
}
public void RumblePulse2(float lowFrequency, float highFrequency, float duration)
{
pad2 = Gamepad.all[1];
if (pad2 != null)
{
pad2.SetMotorSpeeds(lowFrequency, highFrequency);
stopRumbleAfterTimeCorutine = StartCoroutine(stopRumble(duration, pad2));
}
}
private IEnumerator stopRumble(float duration, Gamepad pad)
{
float elapsedTime = 0f;
while (elapsedTime < duration)
{
elapsedTime += Time.deltaTime;
yield return null;
}
pad.SetMotorSpeeds(0f, 0f);
}
}