Skip to content

Instantly share code, notes, and snippets.

@TheStoneBook
Last active July 6, 2018 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheStoneBook/16c327539772d0af517b159ad75fb772 to your computer and use it in GitHub Desktop.
Save TheStoneBook/16c327539772d0af517b159ad75fb772 to your computer and use it in GitHub Desktop.
【Unity】ドラッグで動かしてるCollider2Dと指定のCollider2Dが重なってるかどうかを取得するテスト
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class Collider2DOverlapTest : MonoBehaviour,IDragHandler {
[SerializeField]
private GameObject EnteredObject;
public void OnDrag(PointerEventData data){
Vector3 TargetPos = Camera.main.ScreenToWorldPoint (data.position);
TargetPos.z = 0;
transform.position = TargetPos;
if (EnteredObject.GetComponent<Collider2D> ().OverlapPoint (gameObject.transform.position))
{
Debug.Log ("重なってるよー!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment