Files
Gen_Hack-and-Slash-Roguelit…/Client/Assets/Scripts/Prefab/ImagePrefab.cs

44 lines
1.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Base;
using UnityEngine;
namespace Prefab
{
[RequireComponent(typeof(SpriteRenderer))]
public class ImagePrefab : MonoBehaviour
{
public Sprite defaultSprite;
private SpriteRenderer spriteRenderer;
private void Awake()
{
spriteRenderer = GetComponent<SpriteRenderer>();
if (spriteRenderer == null)
{
Debug.LogError("SpriteRenderer组件未找到请确保预制体包含该组件");
return;
}
if (defaultSprite != null)
{
spriteRenderer.sprite = defaultSprite;
}
}
public void SetSprite(Sprite newSprite)
{
if (spriteRenderer != null && newSprite != null)
{
spriteRenderer.sprite = newSprite;
}
}
public void SetColor(Color newColor)
{
if (spriteRenderer != null)
{
spriteRenderer.color = newColor;
}
}
}
}