| 12345678910111213141516171819202122 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class BreakOnClick : MonoBehaviour
- {
- [Header("破碎效果预制体")]
- public GameObject fractureEffect; // 拖入粒子预制体
- private void OnMouseDown()
- {
- if (fractureEffect != null)
- {
- // 生成粒子效果并自动销毁
- GameObject effect = Instantiate(fractureEffect, transform.position, transform.rotation);
- Destroy(effect, effect.GetComponent<ParticleSystem>().main.duration);
- }
- Destroy(gameObject); // 销毁被点击的物体
- }
- }
|