概要
using System.Collections;
using UnityEngine;
using UnityEngine.InputSystem;
public sealed class Example : MonoBehaviour
{
private void Update()
{
var gamepad = Gamepad.current;
if ( gamepad.aButton.wasPressedThisFrame )
{
StartCoroutine( Vibration( 1, 0 ) );
}
else if ( gamepad.bButton.wasPressedThisFrame )
{
StartCoroutine( Vibration( 0, 1 ) );
}
}
private static IEnumerator Vibration
(
float lowFrequency,
float highFrequency
)
{
var gamepad = Gamepad.current;
gamepad.SetMotorSpeeds( lowFrequency, highFrequency );
yield return new WaitForSeconds( 1f );
gamepad.SetMotorSpeeds( 0, 0 );
}
}
- Unity 2020.3.17f1、Xbox 360 コントローラで動作確認済み
- Switch のプロコンだと振動しなかった