This final puzzle incorporates all the mechanics into this one room where you must hit 3 pressure plates on the wall to proceed.
This is the code for the wall pressure plates.
Once you reach the beacon at the top, the player has to use their electricity to hit it for a few seconds before it explodes. I also added a post-processing box to make the areas more orange.
This is the code for the beacon script. When you step into the range of the sphere collider, the screen begins to shake. Once you hit the electricity into it for a few seconds it then explodes and plays a cutscene.
public Transform playerCam;
public float shakeAmount = 0.2f;
Vector3 originalCamPos;
public GameObject smokeFX, boxVolume, explosionSFX, canvas, beaconFX, beacon, creditsCanvas;
public CanvasGroup canvasGP;
public PlayableDirector player;
private void Start()
{
originalCamPos = playerCam.localPosition;
}
private void OnTriggerStay(Collider other)
{
if (other.CompareTag("Player"))
{
//Screen Shake, End game.
playerCam.localPosition = originalCamPos + Random.insideUnitSphere * shakeAmount;
}
}
private void OnParticleCollision(GameObject other)
{
if (other.CompareTag("Electricity"))
{
StartCoroutine(EndGame());
}
}
IEnumerator EndGame()
{
playerCam.localPosition += originalCamPos + Random.insideUnitSphere * shakeAmount;
yield return new WaitForSeconds(3f);
smokeFX.SetActive(true);
explosionSFX.SetActive(true);
canvas.SetActive(true);
canvasGP.alpha = canvasGP.alpha - Time.deltaTime;
yield return new WaitForSeconds(8f);
canvas.SetActive(false);
boxVolume.SetActive(false);
smokeFX.SetActive(false);
beaconFX.SetActive(false);
beacon.GetComponent<MeshRenderer>().enabled = false;
shakeAmount = 0;
player.enabled = true;
yield return new WaitForSeconds(10f);
creditsCanvas.SetActive(true);
yield return new WaitForSeconds(5f);
Cursor.lockState = CursorLockMode.None;
SceneManager.LoadScene("MainMenu");
if (Input.anyKey)
{
Cursor.lockState = CursorLockMode.None;
SceneManager.LoadScene("MainMenu");
}
}
I also made a short animation clip that will play once you break the beacon which after will then display the credits.
SFX:
https://freesound.org/people/tommccann/sounds/235968/ – Explosion – This was used when the beacon explodes.
https://freesound.org/people/Eponn/sounds/528865/ – Beep – I used this SFX for the wall pressure plates when you hit them.
https://freesound.org/people/MATRIXXX_/sounds/670700/ – BG Ambience – I imported this a while back but forgot to include it in one of these dev logs.