private Vector3 targetPos;
private void Start () {
RaycastHit hit;
// Physics.Raycast(起点坐标,方向,受击物体信息,距离,检测的层)
if (Physics.Raycast(this.transform.position, this.transform.forward, out hit, 100, mask)) {
targetPos = hit.point;
} else {
targetPos = this.transform.position + this.transform.forward * 100
}
}
private void Update () {
this.transform.position = Vector3.MoveTowards(this.transform.position, targetPos, Time.deltaTime * 10);
if ((this.transform.position - targetPos).sqrMagnitude < 0.1f) {
print("接触目标点");
Destory(this.gameObject);
}
}