今天实现了一个小功能,通过移动摄像机实现定位功能功能描述:一开始摄像机处于初始位置,通过点击鼠标选择目标物体将摄像机拉近到目标物体,实现定位功能,
还可以通过回归按钮使摄像机回归到初始状态。
using UnityEngine;
using System.Collections;
public class Sce_09_InstrumentLocating : MonoBehaviour {
public string InstrumentID;
//仪表组件
private Transform obj0;
private Transform obj1;
private Transform obj2;
//摄像机组件
public Transform Cam_transform;
private Vector3 Cam_pos0;
public float smoothTime = 0.5F;
private Vector3 velocity = Vector3.zero;
//偏移量
private Vector3 offset = new Vector3 (10, 10, -10);
public bool isMove;
void MyFunction1(string instrumentid)
{
InstrumentID=instrumentid;
isMove = true;
}
void Start () {
obj1 = GameObject.Find ("压力表1").transform;
obj2 = GameObject.Find ("压力表2").transform;
Cam_transform = Camera.main.transform;
Cam_pos0 = Cam_transform.position; //保存摄像机初始坐标
isMove = false;
}
void Up
Unity 移动摄像机到目标位置
最新推荐文章于 2024-07-20 00:22:56 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)