Sprite 不会改变(和破坏)

问题描述 投票:0回答:1

我想要一个泡泡爆炸,当它被点击但不知何故它不起作用

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 秒后)

c# unity3d
1个回答
0
投票

验证它正在抓取正确的游戏对象。 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);
}
© www.soinside.com 2019 - 2024. All rights reserved.