提交小游戏项目
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Spine.Unity;
|
||||
using UnityEngine;
|
||||
|
||||
public class ParentItem : MonoBehaviour
|
||||
{
|
||||
public List<ChildItem> children = new List<ChildItem>();
|
||||
public SkeletonAnimation destory_ani;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// 自动收集子物体上的 ChildItem 脚本
|
||||
children.AddRange(GetComponentsInChildren<ChildItem>());
|
||||
destory_ani = GetComponentInChildren<SkeletonAnimation>();
|
||||
destory_ani.gameObject.SetActive(false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 当某个子物体被点击时调用
|
||||
public void OnChildClicked(ChildItem child)
|
||||
{
|
||||
Debug.Log($"父物体收到点击事件:{child.name}");
|
||||
// 可以在这里统一管理,比如调用子物体的方法
|
||||
children.Remove(child);
|
||||
if (children.Count <= 0)
|
||||
{
|
||||
// Destroy(gameObject);
|
||||
GetComponent<Collider2D>().enabled = false;
|
||||
GetComponent<SpriteRenderer>().enabled = false;
|
||||
GetComponent<Rigidbody2D>().simulated = false;
|
||||
destory_ani.gameObject.SetActive(true);
|
||||
destory_ani.state.SetAnimation(0, "animation", false);
|
||||
|
||||
destory_ani.state.Complete += (trackEntry) =>
|
||||
{
|
||||
Destroy(gameObject);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user