mirror of
https://github.com/ConjureETS/OuijaMTLGJ2016.git
synced 2026-03-24 10:11:07 +00:00
101 lines
2.4 KiB
C#
101 lines
2.4 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using XInputDotNetPure;
|
|
|
|
[RequireComponent(typeof(Rigidbody))]
|
|
public class SelectorWithBolts : MonoBehaviour
|
|
{
|
|
public Transform[] Bolts;
|
|
public Transform[] RootCylinders;
|
|
public GameObject[] Ropes;
|
|
public Color[] DashColors;
|
|
|
|
private const float DASH_COOLDOWN = 6f;
|
|
|
|
private Rigidbody rb;
|
|
private MeshRenderer[][] playerCylinders;
|
|
|
|
void Awake()
|
|
{
|
|
rb = GetComponent<Rigidbody>();
|
|
|
|
playerCylinders = new MeshRenderer[Ropes.Length][];
|
|
|
|
for (int i = 0; i < Ropes.Length; i++)
|
|
{
|
|
playerCylinders[i] = Ropes[i].GetComponent<Transform>().GetComponentsInChildren<MeshRenderer>();
|
|
}
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
for (int i = 0; i < Ropes.Length; i++)
|
|
{
|
|
ReplenishPlayerDashMeter(i);
|
|
}
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
for (int i = 0; i < RootCylinders.Length; i++)
|
|
{
|
|
Vector3 constraintPos = Bolts[i].position;
|
|
RootCylinders[i].position = constraintPos;
|
|
}
|
|
}
|
|
|
|
public void ReplenishPlayerDashMeter(int playerId)
|
|
{
|
|
ResetRope(playerId);
|
|
|
|
StartCoroutine(ReplenishPlayerDashMeterCoroutine(playerId));
|
|
}
|
|
|
|
private void ResetRope(int playerId)
|
|
{
|
|
foreach (MeshRenderer renderer in playerCylinders[playerId])
|
|
{
|
|
renderer.material.color = Color.gray;
|
|
}
|
|
}
|
|
|
|
private IEnumerator ReplenishPlayerDashMeterCoroutine(int playerId)
|
|
{
|
|
float elapsedTime = 0f;
|
|
|
|
int cylindersCount = playerCylinders[playerId].Length;
|
|
|
|
while (elapsedTime < DASH_COOLDOWN)
|
|
{
|
|
|
|
elapsedTime += Time.deltaTime;
|
|
int cylinderIndex = (int)(elapsedTime * cylindersCount / DASH_COOLDOWN - 1);
|
|
|
|
playerCylinders[playerId][cylinderIndex].material.color = DashColors[playerId];
|
|
|
|
yield return null;
|
|
}
|
|
|
|
StartCoroutine(VibrateController(playerId));
|
|
}
|
|
|
|
private IEnumerator VibrateController(int playerId)
|
|
{
|
|
GamePad.SetVibration((PlayerIndex)playerId, 1f, 1f);
|
|
|
|
yield return new WaitForSeconds(0.5f);
|
|
|
|
GamePad.SetVibration((PlayerIndex)playerId, 0f, 0f);
|
|
}
|
|
|
|
void OnApplicationQuit()
|
|
{
|
|
// In case the coroutine was still running when we closed the game
|
|
|
|
for (int i = 0; i < Bolts.Length; i++)
|
|
{
|
|
GamePad.SetVibration((PlayerIndex)i, 0f, 0f);
|
|
}
|
|
}
|
|
}
|