Cute_demon_attacks/meng_yao/Assets/script/A_Fight/CharacterClick.cs

35 lines
1.2 KiB
C#
Raw Normal View History

2024-12-10 06:57:53 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterClick : MonoBehaviour
{
2024-12-10 07:32:01 +08:00
public Role role;
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD>")] public GameObject panelPrefab;
2024-12-10 06:57:53 +08:00
private void OnMouseDown()
{
// ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2><EFBFBD><EFBFBD> Trigger <20><><EFBFBD><EFBFBD>
Collider2D parentCollider = GetComponent<Collider2D>();
if (parentCollider != null && parentCollider.isTrigger)
{
2024-12-12 17:05:28 +08:00
// parentCollider.enabled = true;
// <20><><EFBFBD>߼<EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǹ<EFBFBD><C7B8>ڵ<EFBFBD>
Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
RaycastHit2D hit = Physics2D.Raycast(mousePosition, Vector2.zero);
if (hit.collider != null && hit.collider.gameObject == gameObject)
{
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD>˸<EFBFBD><CBB8>ڵ<EFBFBD>");
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFB4A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
2024-12-12 17:05:28 +08:00
GameObject instantiatedPanel= GameObject.Instantiate(panelPrefab, GameObject.Find("Canvas").transform);
RectTransform panelRect = instantiatedPanel.GetComponent<RectTransform>();
// ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD><C9B5><EFBFBD><EFBFBD><EFBFBD>ס<E1B5B2><D7A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
panelRect.SetAsLastSibling(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD> Canvas <20><EFBFBD><E3BCB6><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD>
}
}
2024-12-10 06:57:53 +08:00
}
}