forked from zxl/LaboratoryProtection
28 lines
869 B
C#
28 lines
869 B
C#
|
using Sirenix.OdinInspector;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace UnityTest.ZXL
|
|||
|
{
|
|||
|
// [RequireComponent(typeof(BoxCollider2D))]
|
|||
|
[RequireComponent(typeof(BoxCollider), typeof(Rigidbody))]
|
|||
|
public class DragTarget : MonoBehaviour
|
|||
|
{
|
|||
|
[SerializeField] private Transform itemPoint;
|
|||
|
public Vector3 itemPosition => itemPoint.position;
|
|||
|
|
|||
|
#if UNITY_EDITOR
|
|||
|
[Button]
|
|||
|
void Add()
|
|||
|
{
|
|||
|
var rectTransform = gameObject.GetComponent<RectTransform>();
|
|||
|
var rect = rectTransform.rect;
|
|||
|
var boxCollider = GetComponent<BoxCollider>();
|
|||
|
boxCollider.size = new Vector3(rect.width, rect.height, 5);
|
|||
|
boxCollider.isTrigger = true;
|
|||
|
var rigidbody = GetComponent<Rigidbody>();
|
|||
|
rigidbody.useGravity = true;
|
|||
|
rigidbody.isKinematic = true;
|
|||
|
}
|
|||
|
#endif
|
|||
|
}
|
|||
|
}
|