Cute_demon_attacks/meng_yao/Assets/script/A_Fight/BlackHole.cs
2024-12-12 17:05:28 +08:00

33 lines
1.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BlackHole : MonoBehaviour
{
[Header("点击出现的详情")] public GameObject panelPrefab;
[Header("点击出现的详情")] public GameObject parenttransform;
private void OnMouseDown()
{
// 确保父节点的碰撞体是 Trigger 类型
Collider2D parentCollider = GetComponent<Collider2D>();
if (parentCollider != null && parentCollider.isTrigger)
{
// 射线检测鼠标点击的物体是父节点
Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
RaycastHit2D hit = Physics2D.Raycast(mousePosition, Vector2.zero);
if (hit.collider != null && hit.collider.gameObject == gameObject)
{
Debug.Log("点击了父节点");
// 在这里处理点击事件
GameObject obj =GameObject.Instantiate(panelPrefab, GameObject.Find("Canvas").transform);
}
}
}
}