52 lines
1.1 KiB
C#
52 lines
1.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class cardPlace : MonoBehaviour
|
|
{
|
|
private Transform parent;
|
|
public GameObject tower;
|
|
public bool isInTrigger { get; set; }
|
|
|
|
// Start is called before the first frame update
|
|
|
|
private void Start()
|
|
{
|
|
|
|
isInTrigger = false;
|
|
}
|
|
|
|
|
|
private void OnTriggerEnter2D(Collider2D collision)
|
|
{
|
|
if (!isInTrigger)
|
|
{
|
|
//Debug.Log("物体第一次进入触发器");
|
|
isInTrigger = true;
|
|
|
|
}
|
|
}
|
|
|
|
private void OnTriggerExit2D(Collider2D collision)
|
|
{
|
|
if (isInTrigger)
|
|
{
|
|
//Debug.Log("物体退出触发器");
|
|
|
|
isInTrigger = false;
|
|
}
|
|
}
|
|
|
|
private void OnTriggerStay2D(Collider2D collision)
|
|
{
|
|
// 仅在物体持续在触发器内时,执行某些操作
|
|
if (isInTrigger)
|
|
{
|
|
//Debug.Log("物体持续在触发器内");
|
|
// 在这里进行物体持续在触发器内时的操作
|
|
//this.transform.SetParent(collision.transform);
|
|
tower = collision.gameObject;
|
|
}
|
|
}
|
|
}
|