资源简介
此脚本为C#脚本,直接绑定在摄像机上就可以了,注意:End键设置鼠标隐藏和显现,可自己修改。文件仅供学习交流。
代码片段和文件信息
using UnityEngine;
using System.Collections;
public class ExtendedFlycam : MonoBehaviour
{
/*
EXTENDED FLYCAM
Desi Quintans (CowfaceGames.com) 17 August 2012.
based on FlyThrough.js by Slin (http://wiki.unity3d.com/index.php/FlyThrough) 17 May 2011.
LICENSE
Free as in speech and free as in beer.
FEATURES
WASD/Arrows: Movement
Q: Climb
E: Drop
Shift: Move faster
Control: Move slower
End: Toggle cursor locking to screen (you can also press Ctrl+P to toggle play mode on and off).
*/
public float climbSpeed = 4;
public float normalMoveSpeed = 10;
public float slowMoveFactor = 0.25f;
public float fastMoveFactor = 3;
void Start ()
{
Screen.lockCursor = true;
}
void Update ()
{
if (Input.GetKey (KeyCode.LeftShift) || Input.GetKey (KeyCode.RightShift))
{
transform.position += transform.forward * (normalMoveSpeed * fastMoveFactor) * Input.GetAxis(“Vertical“) * Time.deltaTime;
transform.position += transform.right * (normalMoveSpeed * fastMoveFactor) * Input.GetAxis(“Horizontal“) * Time.deltaTime;
}
else if (Input.GetKey (KeyCode.LeftControl) || Input.GetKey (KeyCode.RightControl))
{
transform.position += transform.forward * (normalMoveSpeed * slowMoveFactor) * Input.GetAxis(“Vertical“) * Time.deltaTime;
transform.position += transform.right * (normalMoveSpeed * slowMoveFactor) * Input.GetAxis(“Horizontal“) * Time.deltaTime;
}
else
{
transform.position += transform.forward * normalMoveSpeed * Input.GetAxis(“Vertical“) * Time.deltaTime;
transform.position += transform.right * normalMoveSpeed * Input.GetAxis(“Horizontal“) * Time.deltaTime;
}
if (Input.GetKey (KeyCode.Q)) {transform.position += transform.up * climbSpeed * Time.deltaTime;}
if (Input.GetKey (KeyCode.E)) {transform.position -= transform.up * climbSpeed * Time.deltaTime;}
if (Input.GetKeyDown (KeyCode.End))
{
Screen.lockCursor = (Screen.lockCursor == false) ? true : false;
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3570 2017-08-08 13:35 SmoothMouse.cs
文件 2159 2017-08-08 13:22 ExtendedFlycam.cs
----------- --------- ---------- ----- ----
5729 2
- 上一篇:ASP.NET调用Office组件生成统计图
- 下一篇:C#文本编辑器代码及项目
评论
共有 条评论