using UnityEngine; public class PlayerController : MonoBehaviour { public float jumpForce = 10f; public LayerMask groundLayer; private bool isGrounded; void Update() { // Check if the player is grounded isGrounded = Physics2D.IsTouchingLayers(GetComponent(), groundLayer); // Jump if spacebar is pressed and the player is grounded if (isGrounded && Input.GetKeyDown(KeyCode.Space)) { GetComponent().velocity = new Vector2(0, jumpForce); } } } using UnityEngine; using UnityEngine.SceneManagement; public class Obstacle : MonoBehaviour { void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.CompareTag("Player")) { // Reload the scene if the player hits an obstacle SceneManager.LoadScene(SceneManager.GetActiveScene().name); } } } using UnityEngine; public class LevelMovement : MonoBehaviour { public float moveSpeed = 5f; void Update() { // Move the level from right to left transform.Translate(Vector2.left * moveSpeed * Time.deltaTime); } } using UnityEngine; public class AudioSync : MonoBehaviour { public AudioSource audioSource; public float[] spectrum; void Update() { spectrum = new float[256]; audioSource.GetSpectrumData(spectrum, 0, FFTWindow.Rectangular); // Adjust the level's movement speed based on the audio beat (low frequency) float beat = Mathf.Clamp01(spectrum[0]); float beatSpeed = Mathf.Lerp(5f, 10f, beat); // Adjust the level movement speed according to the audio beat GameObject.FindObjectOfType().moveSpeed = beatSpeed; } } using UnityEngine; using UnityEngine.SceneManagement; public class GameManager : MonoBehaviour { public void RestartLevel() { // Reload the current scene SceneManager.LoadScene(SceneManager.GetActiveScene().name); } } using UnityEngine; using UnityEngine.UI; public class UIManager : MonoBehaviour { public GameObject startScreen; public GameObject gameOverScreen; public GameObject gameplayUI; public void ShowStartScreen() { startScreen.SetActive(true); gameOverScreen.SetActive(false); gameplayUI.SetActive(false); } public void ShowGameplayUI() { startScreen.SetActive(false); gameOverScreen.SetActive(false); gameplayUI.SetActive(true); } public void ShowGameOverScreen() { startScreen.SetActive(false); gameOverScreen.SetActive(true); gameplayUI.SetActive(false); } public void StartGame() { ShowGameplayUI(); } public void RestartGame() { SceneManager.LoadScene(SceneManager.GetActiveScene().name); } }