unity实现摄像头跟随
作者:hebedich 时间:2021-07-26 12:50:10
代码很简单,这里就不多废话了,直接奉上代码
using UnityEngine;
using System.Collections;
public class FllowTarget : MonoBehaviour {
public Transform character; //摄像机要跟随的人物
public float smoothTime = 0.01f; //摄像机平滑移动的时间
private Vector3 cameraVelocity = Vector3.zero;
private Camera mainCamera; //主摄像机(有时候会在工程中有多个摄像机,但是只能有一个主摄像机吧)
void Awake ()
{
mainCamera = Camera.main;
}
void Update()
{
transform.position = Vector3.SmoothDamp(transform.position, character.position + new Vector3(0, 0, -5), ref cameraVelocity, smoothTime);
}
}
以上所述就是本文的全部内容了,希望大家能够喜欢,能够对大家学习unity有所帮助。
标签:unity,摄像头跟随
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Git和Maven的子模块简单实践
2023-09-22 01:45:55
mybatis中的缓存问题解析
2023-07-27 20:01:59
![](https://img.aspxhome.com/file/2023/0/103820_0s.png)
springBoot接入阿里云oss的实现步骤
2023-05-28 23:09:04
![](https://img.aspxhome.com/file/2023/2/110872_0s.png)
使用Java8实现模板方法模式的改造
2021-10-28 23:46:09
java并发编程_线程池的使用方法(详解)
2023-03-29 22:23:00
![](https://img.aspxhome.com/file/2023/1/69711_0s.png)
C#读写文件的方法汇总
2022-03-01 04:41:41
Android Studio 3.x版本 的输入法遇到的坑及解决方案
2023-03-19 03:13:40
![](https://img.aspxhome.com/file/2023/1/114301_0s.jpg)
Springboot+SpringSecurity+JWT实现用户登录和权限认证示例
2021-11-14 11:06:11
![](https://img.aspxhome.com/file/2023/3/71583_0s.png)
详解java中接口与抽象类的区别
2021-09-12 03:21:39
android使用ExpandableListView控件实现小说目录效果的例子
2023-04-14 22:10:27
Java事务管理学习之Spring和Hibernate详解
2023-04-11 00:01:25
![](https://img.aspxhome.com/file/2023/4/62684_0s.png)
C#基于Mongo的官方驱动手撸一个Super简易版MongoDB-ORM框架
2021-06-05 17:27:50
![](https://img.aspxhome.com/file/2023/2/105852_0s.png)
Redisson RedLock红锁加锁实现过程及原理
2022-12-29 20:49:42
SpringBoot项目的logback日志配置(包括打印mybatis的sql语句)
2021-08-24 02:15:22
![](https://img.aspxhome.com/file/2023/7/63767_0s.png)
C#环形缓冲区(队列)完全实现
2022-06-26 08:05:48
Java如何使用ReentrantLock实现长轮询
2023-11-26 00:09:08
详解C#借助.NET框架中的XmlTextReader类读取XML的方法
2023-01-18 23:31:47
![](https://img.aspxhome.com/file/2023/8/75578_0s.jpg)
Android调用google地图生成路线图实现代码
2023-06-04 09:37:25
深入探讨Java多线程中的volatile变量
2023-08-31 02:32:18
总结Java的Struts框架的异常处理方法
2022-04-12 01:29:44
![](https://img.aspxhome.com/file/2023/1/108431_0s.jpg)