Unity3d入门代码--摄像机跟随
2017-04-14 09:17
537 查看
Unity3d入门代码–摄像机跟随
摄像机跟随的代码
代码
using System.Collections; using System.Collections.Generic; using UnityEngine; public class camerafollow : MonoBehaviour { public Transform target; //要跟随的目标 public float speed = 5f; //摄像机平滑速度 Vector3 offset; //目标与摄像机之间偏差值(距离) void Awake() { offset = transform.position - target.position; //计算出offset } void FixedUpdate() { Vector3 targetcampos = target.position + offset; //摄像机将要去的位置 transform.position = Vector3.Lerp(transform.position,targetcampos,speed*Time.deltaTime);//Lerp(现在的位置,目的地位置,持续时间) //Lerp函数是插值函数 } }
最后不要忘记在unity编辑器中给target赋值
相关文章推荐
- unity3d阶段性学习脚本代码(2个是摄像机跟随(2D游戏中的),1个是角色跳跃移动脚本)
- Unity3D脚本:摄像机自动适应所有分辨率代码
- Unity3D入门 第捌章: 多个摄像机之间的切换
- unity3d相机跟随物体平滑移动(C#代码)
- Unity3d--摄像机跟随 第三人称常用方式
- Unity3D ----- 代码控制shader的自发光参数(摄像机黑白特效下)
- unity3d 摄像机跟随角色时被物体遮挡解决方案
- 第三人视角,摄像机跟随代码
- Unity3d学习记录(一)摄像机跟随人物移动,并且注视人物
- 【Unity3D游戏开发学习笔记】(七)上帝之眼—第三人称摄像机的简单实现(跟随视角,自由视角)
- Unity3D入门(四):摄像机控制
- Unity3D 摄像机滑动跟随
- Unity3D入门: 多个摄像机之间的切换
- 第三人视角,摄像机跟随代码
- unity3d 摄像机跟随角色时被物体遮挡解决方案
- Unity3D 摄像机跟随强烈抖动问题
- 【Unity3D自学记录】NGUI之编写跟随鼠标代码
- Unity3D入门(五):鼠标控制旋转、摄像机缩放
- Unity3D 摄像机平滑跟随角色
- Unity3D中摄像机跟随方法