速度太快的话,一样会穿透过去。
上图,中间是个可移动的模型,两边Cube限制点:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CarTrigger : MonoBehaviour {
public GameObject Point1;//限制点1
public GameObject Point2;//限制点2
public float carSpeed = 6f;//移动速度
public bool isTrigger = false;//是否是触发状态
void Update () {
float v = Input.GetAxis("Vertical");//垂直向量的输入
if (isTrigger==false)//如果不是触发状态
{
//用户按下了W或者S
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S))
{