Resolving error

This commit is contained in:
hz
2026-01-30 20:53:52 -06:00
parent 4a291594da
commit ed54714b1c
8 changed files with 195 additions and 227 deletions
+29
View File
@@ -0,0 +1,29 @@
using UnityEngine;
[RequireComponent(typeof(SpriteRenderer))]
public class AutoSquareSprite : MonoBehaviour
{
private static Sprite cachedSquare;
private void Awake()
{
var spriteRenderer = GetComponent<SpriteRenderer>();
if (spriteRenderer.sprite != null)
{
return;
}
if (cachedSquare == null)
{
var texture = Texture2D.whiteTexture;
cachedSquare = Sprite.Create(
texture,
new Rect(0f, 0f, texture.width, texture.height),
new Vector2(0.5f, 0.5f),
1f);
cachedSquare.name = "RuntimeSquare";
}
spriteRenderer.sprite = cachedSquare;
}
}