TO SQUASH: Added background.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(SpriteRenderer))]
|
||||
public class GameBoard : MonoBehaviour
|
||||
{
|
||||
private SpriteRenderer spriteRenderer;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
ResetBoard();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void ResetBoard()
|
||||
{
|
||||
// Reset the game board to its initial state
|
||||
int currentLevel = PlayerPrefs.GetInt("CurrentLevel");
|
||||
currentLevel = currentLevel == 0 ? 1 : currentLevel; // Ensure currentLevel is at least 1
|
||||
currentLevel = (((currentLevel - 1) / 5) % 10 + 10) % 10 + 1;
|
||||
|
||||
Debug.Log($"Current Level: {currentLevel}");
|
||||
|
||||
string resourcePath = $"Patterns/fore_{currentLevel}";
|
||||
|
||||
Texture2D texture = Resources.Load<Texture2D>(resourcePath);
|
||||
if (texture == null)
|
||||
{
|
||||
Debug.LogWarning($"Could not load Sprite or Texture2D at Resources/{resourcePath}");
|
||||
return;
|
||||
}
|
||||
|
||||
// Fallback if the asset is imported as Texture instead of Sprite.
|
||||
Sprite runtimeSprite = Sprite.Create(
|
||||
texture,
|
||||
new Rect(0, 0, texture.width, texture.height),
|
||||
new Vector2(0.5f, 0.5f),
|
||||
100f
|
||||
);
|
||||
|
||||
spriteRenderer.sprite = runtimeSprite;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2fc998065c092c32ba2452cd6a674a11
|
||||
@@ -0,0 +1,50 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class MusicManager : MonoBehaviour
|
||||
{
|
||||
public AudioClip intro;
|
||||
|
||||
public AudioClip loop;
|
||||
|
||||
public AudioClip outro;
|
||||
|
||||
private AudioSource audioSource;
|
||||
|
||||
private Queue<AudioClip> clipsQueue;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
clipsQueue = new Queue<AudioClip>();
|
||||
|
||||
// Intro is only played once, so we enqueue it first.
|
||||
clipsQueue.Enqueue(intro);
|
||||
ResetQueue();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate()
|
||||
{
|
||||
if (audioSource.isPlaying == false)
|
||||
{
|
||||
audioSource.clip = clipsQueue.Dequeue();
|
||||
audioSource.Play();
|
||||
|
||||
if(clipsQueue.Count == 0)
|
||||
{
|
||||
ResetQueue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetQueue()
|
||||
{
|
||||
clipsQueue.Enqueue(loop);
|
||||
clipsQueue.Enqueue(loop);
|
||||
clipsQueue.Enqueue(loop);
|
||||
clipsQueue.Enqueue(loop);
|
||||
clipsQueue.Enqueue(outro);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f5ef1cb3ef8c59863b1d7c11e4d37e5c
|
||||
Reference in New Issue
Block a user