标签:vat nio put date() generic distance ble 鼠标 距离
1 using System.Collections; 2 using System.Collections.Generic; 3 using UnityEngine; 4 5 public class CameraFollow_A : MonoBehaviour 6 { 7 public Transform target; //目标对象 8 private Vector3 offset; //距离差 9 10 void Start() 11 { 12 offset = target.position - this.transform.position; 13 } 14 15 void Update() 16 { 17 this.transform.position = target.position - offset; 18 } 19 }
1 using System.Collections; 2 using System.Collections.Generic; 3 using UnityEngine; 4 5 public class CameraFollow_B : MonoBehaviour 6 { 7 private Transform target; //目标对象 8 private Vector3 offset = new Vector3(0, 7, -6); //相机与目标对象的相对位置 9 private Vector3 pos; 10 public float speed = 2; //旋转的平滑速度 11 12 void Start() 13 { 14 //利用标签Tag锁定所要跟随的目标对象 15 target = GameObject.FindGameObjectWithTag("Player").transform; 16 } 17 18 void Update() 19 { 20 pos = target.position + offset; 21 this.transform.position = Vector3.Lerp(this.transform.position, pos, speed * Time.deltaTime); //调整相机与目标对象的距离 22 Quaternion angel = Quaternion.LookRotation(target.position - this.transform.position); //获取旋转角度 23 this.transform.rotation = Quaternion.Slerp(this.transform.rotation, angel, speed * Time.deltaTime); 24 } 25 }
1 using System.Collections; 2 using System.Collections.Generic; 3 using UnityEngine; 4 5 public class CameraFollow_C : MonoBehaviour 6 { 7 public Transform target; //目标对象 8 9 public float distanceUp = 8f; //相机与目标对象竖直方向的距离 10 public float distanceAway = 10f; //相机与目标对象前后方向的距离 11 public float smooth = 10f; //移动平滑值 12 13 void Update() 14 { 15 // 通过鼠标轴控制相机的远近 16 if ((Input.mouseScrollDelta.y < 0 && Camera.main.fieldOfView >= 3) || 17 Input.mouseScrollDelta.y > 0 && Camera.main.fieldOfView <= 80) 18 { 19 Camera.main.fieldOfView += Input.mouseScrollDelta.y * Time.deltaTime; 20 } 21 } 22 23 void LateUpdate() 24 { 25 //更新相机的位置 26 Vector3 disPos = target.position + Vector3.up * distanceUp - target.forward * distanceAway; 27 transform.position = Vector3.Lerp(transform.position, disPos, Time.deltaTime * smooth); 28 //更新相机的角度 29 transform.LookAt(target.position); 30 } 31 }
1 using System.Collections; 2 using System.Collections.Generic; 3 using UnityEngine; 4 5 public class CameraFollow_D : MonoBehaviour 6 { 7 public Transform target; //目标对象 8 private Vector3 Rotion_Transform; 9 private new Camera camera; 10 11 void Start() 12 { 13 camera = GetComponent<Camera>(); 14 Rotion_Transform = target.position; 15 } 16 17 void Update() 18 { 19 Rotate(); 20 Scale(); 21 } 22 23 //相机的上下左右旋转 24 private void Rotate() 25 { 26 var mouse_x = Input.GetAxis("Mouse X");//获取鼠标X轴移动 27 var mouse_y = -Input.GetAxis("Mouse Y");//获取鼠标Y轴移动 28 if (Input.GetKey(KeyCode.Mouse0)) 29 { 30 transform.RotateAround(Rotion_Transform, Vector3.up, mouse_x * 5); 31 transform.RotateAround(Rotion_Transform, transform.right, mouse_y * 5); 32 } 33 } 34 35 //相机的视角缩放 36 private void Scale() 37 { 38 if (Input.GetAxis("Mouse ScrollWheel") > 0) 39 { 40 transform.Translate(Vector3.forward * 1f);//速度可调 自行调整 41 } 42 if (Input.GetAxis("Mouse ScrollWheel") < 0) 43 { 44 transform.Translate(Vector3.forward * -1f);//速度可调 自行调整 45 } 46 } 47 }
标签:vat nio put date() generic distance ble 鼠标 距离
原文地址:https://www.cnblogs.com/ChenZiRong1999/p/12938976.html