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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user