基于Unity3D的相机功能的实现(六)—— 上帝视角(王者荣耀视角)
在MOBA游戏中,上帝视角是一个很实用的功能。
代码如下:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;//上帝视角(王者荣耀视角)
public class OverlookCamera : MonoBehaviour
{//Camera 水平移动速度public float speedH = 20f;//Camera 垂直移动速度public float speedV = 20f;//x方向最小值public float minX = -67f;//x方向最大值public float maxX = 70f;//y方向最小值public float minY = -75f;//y方向最大值public float maxY = 50f;//插值速度public float lerpSpeed=4f;//位置插值目标 private Vector3 posTarget;//屏幕的宽度private float screenWidth;//屏幕的高度private float screenHeight;void Start(){screenWidth = Screen.width;screenHeight = Screen.height;posTarget = transform.position;}void Update(){if (Input.touchCount == 1) {Vector2 touchPos = Input.GetTouch (0).position;if (touchPos.x >= screenWidth - 40 && Input.GetTouch (0).phase == TouchPhase.Stationary) {if (transform.position.x <= maxX)posTarget = posTarget + Vector3.right * speedH * 0.02f;} else if (touchPos.x <= 40 && Input.GetTouch (0).phase == TouchPhase.Stationary) {if (transform.position.x >= minX)posTarget = posTarget + Vector3.left * speedH * 0.02f;} else if (touchPos.y > screenHeight - 40 && Input.GetTouch (0).phase == TouchPhase.Stationary) {if (transform.position.z <= maxY)posTarget = posTarget + Vector3.forward * speedV * 0.02f;} else if (touchPos.y < 40 && Input.GetTouch (0).phase == TouchPhase.Stationary) {if (transform.position.z >= minY)posTarget = posTarget + Vector3.back * speedV * 0.02f;} else {float x = Input.GetAxis ("Mouse X");float y = Input.GetAxis ("Mouse Y");//x方向在最大值和最小值if (transform.position.x >= minX && transform.position.x <= maxX) {if (x < -0.1f) {posTarget = posTarget + Vector3.right * -speedH * 0.02f;} else if (x > 0.1f) {posTarget = posTarget + Vector3.left * -speedH * 0.02f;}} else {//x小于最小值if (transform.position.x < minX) {if (x > 0.1f) {posTarget = posTarget + Vector3.left * -speedH * 0.02f;}}//x大于最小值else {if (x < -0.1f) {posTarget = posTarget + Vector3.right * -speedH * 0.02f;}}}//y方向在最大值和最小值if (transform.position.z >= minY && transform.position.z <= maxY) {if (y < -0.1f) {posTarget = posTarget + Vector3.forward * -speedV * 0.02f;} else if (y > 0.1f) {posTarget = posTarget + Vector3.back * -speedV * 0.02f;}} else {//y小于最小值if (transform.position.z < minY) {if (y > 0.1f) {posTarget = posTarget + Vector3.back * -speedV * 0.02f;}}//y大于最小值else {if (y < -0.1f) {posTarget = posTarget + Vector3.forward * -speedV * 0.02f;}}}}}}void LateUpdate (){if (Vector3.Distance (posTarget, transform.position) > 0.01f) {transform.position = Vector3.Lerp (transform.position, posTarget, Time.deltaTime * lerpSpeed);} else {transform.position = posTarget;}}
}
基于Unity3D的相机功能的实现(六)—— 上帝视角(王者荣耀视角)相关推荐
- 基于Unity3D的相机功能的实现(一)——VR相机
Unity自带陀螺仪功能,今天就利用陀螺仪实现一个VR相机功能.步骤如下: 打开Unity,创建一个新的C#脚本GyroController.cs,并挂在MainCamera游戏对象上,代码如下: u ...
- 基于Unity3D的相机功能的实现(二)——AR相机
AR相机的实现,功能包括: 1.双指进行放大缩小操作: 2.单指水平滑动时,水平旋转: 3.单指垂直滑动时,垂直旋转. 代码如下: using UnityEngine; using System.Co ...
- 我和AI打了六局王者荣耀,心态崩了
十三 发自 凹非寺 量子位 报道 | 公众号 QbitAI 今天,我和AI绝悟打了6局王者荣耀,心态有点崩. 没赢过?不,比分3:3打平,还拿过MVP. 那怎么就崩溃了?听我慢慢道来. PVP对战手游 ...
- 基于Unity3D的绘画功能实现
using UnityEngine; using System.Collections; /// <summary> /// 鼠标画图功能 /// </summary> pub ...
- 自建比赛服务器,王者荣耀自建比赛创建功能是什么 王者荣耀如何创建自建比赛...
王者荣耀自建比赛创建功能是什么呢?今天由玩家发现王者荣耀更新之后带来了一个全新的功能,那就是自建比赛创建功能,这个自建比赛是什么呢?很多玩家还不是特别清楚,今天小编便给大家带来王者荣耀自建比赛创建功 ...
- 王者荣耀服务器信息共享,《王者荣耀》上线“账号时长共享”功能:微信/QQ合二为一...
腾讯健康系统最近频繁做出大升级,本月启动了中国大陆地区<王者荣耀>用户强制公安实名校验的工作,现在连微信/QQ账号时长也共享了. 腾讯宣布,今天起,以北京地区为起点,腾讯将在<王者荣 ...
- 王者荣耀服务器信息共享,腾讯将在《王者荣耀》中启用“账号时长共享”新功能...
新浪科技讯 11月15日下午消息,今日,官方发布声明称,为更好保护未成年人健康上网,今起,以北京地区为起点,腾讯将在<王者荣耀>中启用"账号时长共享"的新功能:同时,以 ...
- 基于消失点的相机自标定(2)
点云PCL免费知识星球,点云论文速读. 标题:Camera calibration using two or three vanishing points 作者:Radu Orghidan∗, Joa ...
- unity 陶瓷质感_一种基于Unity3D的虚拟陶瓷设计方法与流程
本发明涉及虚拟现实领域,特别涉及一种基于Unity3D的虚拟陶瓷设计方法. 背景技术: 陶艺工艺制作环境要求严格:不仅在拉坯成型需要利用旋转机器,在烧制过程则需要窑炉锻造,如何将陶瓷制作工艺与虚拟现实 ...
最新文章
- [Win]进程间通信——邮槽Mailslot
- mysql exists in join_子查询、left join、 exists 替代 not in
- 获取会话名称时错误 5_2019Java面试宝典系列|基础篇5
- 联发科发布天玑5G开放架构 采用该定制芯片终端7月上市
- OpenMP变量的私有与共享
- 东莞城院c语言上机报告,浙大城市学院c语言上机试题
- poj 3335 Rotating Scoreboard - 半平面交
- Linux运维之ntpdate同步网络时间
- cd oracle home/dbs,Oracle专家高级编程学习笔记
- 2018年华北五省计算机应用大赛参赛作品--战拖儿app
- 零件测绘与计算机作图理论试题,浅谈《零部件测绘与cad成图技术》技能竞赛对中职机械制图和cad制图课程整合的影响...
- 免ROOT的计算机隐藏应用软件,AppHider隐藏应用
- 网络安全技术(第4版)复习资料整理
- java线程栅栏_java多线程 栅栏CyclicBarrier
- ajax四个常用参数,ajax 常用参数
- Android使用exchange日历,使用Exchange服务实现跨平台(PC+Web + 移动端)日历的日程管理...
- 自动化测试-数据驱动
- 如何将word自带的公式快速转为latex?
- 如何做H5页面阴影悬浮效果
- mysql数据库工程师 课程_数据库开发工程师需要学习哪些课程?