49 lines
1.1 KiB
C#
49 lines
1.1 KiB
C#
|
using System.Collections;
|
||
|
using System.Linq;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.InputSystem;
|
||
|
|
||
|
public class RopeRumbling : MonoBehaviour
|
||
|
{
|
||
|
[SerializeField] private float RopeRubleTolerance = 0.5f;
|
||
|
[SerializeField] private float MaxVibration = 0.8f;
|
||
|
|
||
|
private PlayerInput pInput;
|
||
|
private Gamepad pad;
|
||
|
|
||
|
// Rope
|
||
|
[SerializeField] private RopeSimulator rope;
|
||
|
|
||
|
private void Start()
|
||
|
{
|
||
|
Invoke("LateStart", 0.1f);
|
||
|
}
|
||
|
|
||
|
void LateStart()
|
||
|
{
|
||
|
pInput = GetComponent<PlayerInput>();
|
||
|
pad = Gamepad.all.ElementAtOrDefault(pInput.PlayerNum);
|
||
|
if (pad == null)
|
||
|
{
|
||
|
this.enabled = false;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
hasInit = true;
|
||
|
}
|
||
|
|
||
|
bool hasInit = false;
|
||
|
private void Update()
|
||
|
{
|
||
|
if (!hasInit) return;
|
||
|
|
||
|
float ropeClamed = Mathf.Max(0, rope.Overshoot);
|
||
|
float sensitive_mapped = ropeClamed.Remap(0.2f, 1f, 0f, MaxVibration);
|
||
|
float mapped = ropeClamed.Remap(0.5f, 1f, 0f, MaxVibration);
|
||
|
RumbleManager.StartRumble(-1, sensitive_mapped, mapped, 0.1f);
|
||
|
}
|
||
|
}
|