精灵不会改变(和销毁)

huangapple go评论63阅读模式
英文:

Sprite doesn't change (and destroying)

问题

我希望当点击时,气泡会爆炸,但不知何故它不起作用

使用UnityEngine;

public class BCE : MonoBehaviour
{
public Sprite poppedSprite;
public float destroyDelay = 1f;

private bool isPopped = false;

private void OnMouseDown()
{
    // 更改精灵为"popped"精灵
    gameObject.GetComponent<SpriteRenderer>().sprite = poppedSprite;
    // 设置指示气泡已经爆炸的标志
    isPopped = true;
    // 在短暂延迟后销毁游戏对象
    Destroy(this.gameObject, 0.1f);
}

}


气泡必须更改其精灵并销毁(0.1秒后)

<details>
<summary>英文:</summary>

I wanted a bubble to explode, when it&#39;s clicked but it doesnt work somehow

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 &quot;popped&quot; sprite
    gameObject.GetComponent&lt;SpriteRenderer&gt;().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);
}

}


The bubble must change it&#39;s sprite and destroy (after 0.1 seconds)

</details>


# 答案1
**得分**: 0

Verify that it's grabbing the proper gameObject. 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);
}

<details>
<summary>英文:</summary>

Verify that it&#39;s grabbing the proper gameObject. Debug.Log(this.gameObject.name)

    private void OnMouseDown()
    {
        // Change the sprite to the &quot;popped&quot; sprite
        gameObject.GetComponent&lt;SpriteRenderer&gt;().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);
    }

</details>



huangapple
  • 本文由 发表于 2023年3月3日 22:40:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75628457.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定