我想要一个泡泡爆炸,当它被点击但不知何故它不起作用
using UnityEngine;
public class BCE : MonoBehaviour
{
public Sprite poppedSprite;
public float destroyDelay = 1f;
private bool isPopped = false;
private void OnMouseDown()
{
// Change the sprite to the "popped" sprite
gameObject.GetComponent<SpriteRenderer>().sprite = poppedSprite;
// Set the flag indicating that the bubble has been popped
isPopped = true;
// Destroy the GameObject after a short delay
Destroy(this.gameObject, 0.1f);
}
}
泡泡必须改变它的精灵并销毁(0.1 秒后)
验证它正在抓取正确的游戏对象。 Debug.Log(this.gameObject.name)
private void OnMouseDown()
{
// Change the sprite to the "popped" sprite
gameObject.GetComponent<SpriteRenderer>().sprite = poppedSprite;
// Set the flag indicating that the bubble has been popped
isPopped = true;
Debug.Log(this.gameObject.name)
// Destroy the GameObject after a short delay
Destroy(this.gameObject, 0.1f);
}