unity实现吸附功能的效果随笔
物体移动到墙体一定距离会被吸附到墙体上面
这个一定的距离根据代码
Vector3 scale = boxCol.transform.localScale+ new Vector3(1.4f,0,0);
来更改;
代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//using DG.Tweening;
public class Wallcollision : MonoBehaviour
{
BoxCollider boxCol = null;
private void Start()
{
boxCol = GetComponent<BoxCollider>();
}
private void Update()
{
DetectionBox(