找回密码
 立即注册
查看: 478|回复: 0

Unity不同游戏里,有不同的Camera,这里简单介绍下。

[复制链接]
发表于 2021-11-23 14:57 | 显示全部楼层 |阅读模式
官方标准资源提供了4种Camera
对惹,这里有一个游戏开发交流小组,希望大家可以点击进来一起交流一下开发经验呀~
CctvCamera
这种类似于电视转播的摄像机看到的情形,摄像机固定在远处,通过转动角度,跟踪拍摄对象,类似于足球游戏常会用到的视角。
将预制件拖到场景中,位置最好离对象远点,将对象拖到Target里,可以通过调节Field View来控制对象显示的大小,相当于在调整焦距。

FreeLookCamera
这个是会将对象一直显示在屏幕中,可以通过鼠标上下左右移动观看周围,和魔兽世界里面按下鼠标左键以后的那个视角一样。
将预制件拖到场景,位置会自己去定,将对象拖到Target里,可以通过FreeLookCameraRig的孙子对象的Field View来控制对象显示的大小,相当于在调整焦距。



HandHeldCamera
这个像是一个可以自动变焦,可以保持对象显示大小始终一致的CctvCamera
将预制件拖到场景,位置会自己去定,将对象拖到Target里,可以通过Zoom Amount Multiplier来调整最初的焦距。



第一人称视角
Unity的第一人称视角是和控制和在一起的一个预制件,直接拖到场景中就可以用了。



以上是Unity标准资源里的,下面再介绍几个其他的
LookAtCamera
这个可以理解为CctvCamera的简化版,代码如下
把脚本拖到Camera上,然后设置target对象即可。
using UnityEngine;
public class LookAtCamera : MonoBehaviour
{
publicGameObject target;
voidLateUpdate ()
{
transform.LookAt(target.transform);
}
}
DungeonCamera
Camera和对象的距离和角度始终保持不变,类似于暗黑破坏神的视角
把脚本拖到Camera上,然后设置target对象即可。
using UnityEngine;
public class DungeonCamera : MonoBehaviour
{
publicGameObject target;
publicfloat damping = 5;
Vector3offset;
voidStart() {
offset= transform.position - target.transform.position;
}
voidLateUpdate() {
if(damping > 0) {
Vector3desiredPosition = target.transform.position + offset;
Vector3position = Vector3.Lerp (transform.position, desiredPosition, Time.deltaTime *damping);
transform.position= position;
transform.LookAt(target.transform.position);
}else {
Vector3desiredPosition = target.transform.position + offset;
transform.position= desiredPosition;
}
}
}
FollowCamera
Camera始终在对象后方的同时,Camera的正前方始终和对象的正前方保持一致,随对象旋转而旋转。类似神庙逃亡的视角,或者是魔兽世界默认的视角。
把脚本拖到Camera上,然后设置target对象即可。
using UnityEngine;
public class FollowCamera : MonoBehaviour {
publicGameObject target;
publicfloat damping = 1;
Vector3offset;
voidStart(){
offset= target.transform.position - transform.position;
}
voidLateUpdate(){
if(damping > 0) {
floatcurrentAngle = transform.eulerAngles.y;
floatdesiredAngle = target.transform.eulerAngles.y;
floatangle = Mathf.LerpAngle (currentAngle, desiredAngle, Time.deltaTime * damping);
Quaternionrotation = Quaternion.Euler (0, angle, 0);
transform.position= target.transform.position - (rotation * offset);
transform.LookAt(target.transform);
}else{
floatdesireAngle = target.transform.eulerAngles.y;
Quaternionrotation = Quaternion.Euler (0, desireAngle, 0);
transform.position= target.transform.position - (rotation * offset);
transform.LookAt(target.transform);
}

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-9-23 03:26 , Processed in 0.157591 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表