1.固定距离移动
点击某物体相机移动到该物体的固定距离的位置
脚本添加到被点击物体上
using System.Collections.Generic;using UnityEngine;using UnityEngine.EventSystems;using DG.Tweening; //动画插件public class test:MonoBehaviour, IPointerClickHandler{ Camera mainCamera; Vector3 offset, pos; bool isClick; private void Start() { mainCamera = GameObject.Find("Main Camera").GetComponent<Camera>(); offset = new Vector3(-0.2f, -10.27f, 10.86f); // 指定一个物体 A世界位置-相机位置B获得向量 pos = transform.parent.TransformPoint(transform.localPosition) -offset; // 世界位置-偏移向量 } private void Update() { if (isClick) { mainCamera.transform.DOMove(pos, .5f); isClick = false; } } public void OnPointerClick(PointerEventData eventData) { isClick = true; }}