英文:
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'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 "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);
}
}
The bubble must change it'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'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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论