unity中实现的第三人称摄像机控制脚本。
2016-01-22 12:21
459 查看
using UnityEngine;
[RequireComponent( typeof( Camera ) )]
public class ThirdPersonCamera : MonoBehaviour
{
public Transform follow;
public float m_fDistance = 7.0f;
public float m_fXSpeed = 350.0f;
public float m_fYMinLimit= 0.1f;
public float m_fYMaxLimit = 89.9f;
private float m_fXRot = 0.0f;
public float m_fYRot = 0.0f;
public float
speed = 5.0f;
void Start()
{
follow=follow?follow:GameObject.Find("Player").transform;
}
void LateUpdate(){
if(Input.GetMouseButton(0)){
m_fXRot += Input.GetAxis("Mouse X")/10.0f * m_fXSpeed;
m_fYRot -= Input.GetAxis("Mouse Y")/10.0f * m_fXSpeed;
}
m_fYRot = Mathf.Clamp(m_fYRot,m_fYMinLimit, m_fYMaxLimit);
Vector3 negDistance= new Vector3(0.0f, 0.0f, -m_fDistance);
//transform.rotation = Quaternion.Lerp(transform.rotation,Quaternion.Euler(m_fYRot, m_fXRot, 0),Time.deltaTime*speed);
transform.rotation =Quaternion.Euler(m_fYRot, m_fXRot, 0);
transform.position = transform.rotation * negDistance + follow.position;
}
}
[RequireComponent( typeof( Camera ) )]
public class ThirdPersonCamera : MonoBehaviour
{
public Transform follow;
public float m_fDistance = 7.0f;
public float m_fXSpeed = 350.0f;
public float m_fYMinLimit= 0.1f;
public float m_fYMaxLimit = 89.9f;
private float m_fXRot = 0.0f;
public float m_fYRot = 0.0f;
public float
speed = 5.0f;
void Start()
{
follow=follow?follow:GameObject.Find("Player").transform;
}
void LateUpdate(){
if(Input.GetMouseButton(0)){
m_fXRot += Input.GetAxis("Mouse X")/10.0f * m_fXSpeed;
m_fYRot -= Input.GetAxis("Mouse Y")/10.0f * m_fXSpeed;
}
m_fYRot = Mathf.Clamp(m_fYRot,m_fYMinLimit, m_fYMaxLimit);
Vector3 negDistance= new Vector3(0.0f, 0.0f, -m_fDistance);
//transform.rotation = Quaternion.Lerp(transform.rotation,Quaternion.Euler(m_fYRot, m_fXRot, 0),Time.deltaTime*speed);
transform.rotation =Quaternion.Euler(m_fYRot, m_fXRot, 0);
transform.position = transform.rotation * negDistance + follow.position;
}
}
相关文章推荐
- Unity C#和OC互相调用
- unity中的简单水效果实现
- unity3d用鼠标拖动物体的一段代码
- Unity3D场景漫游以及碰撞防止反弹
- unity5.3 场景烘焙
- Unity3D读取模型文件自动生成AnimatorController简单实例
- 有关unity3d 输入与控制(键盘与鼠标输入控制)
- 今日推荐。基于unity的游戏开发视频,适合自学。
- 初学unity(让场景动起来)
- Unity3D Ios 打包注意事项
- Unity3D中的shader,视角,和贴图范围offset
- UNITY 5.3.1 发行说明 中文版
- 《Unity_API解析》 第一章 Application类
- xlsxtools游戏配置表工具,开源跨平台,支持多语言,Unity3D等游戏引擎使用Excel做游戏配置表的解决方案
- unity3d编程日志
- Windows7下Visual Studio 2015 Community + opencv3.1.0环境搭建
- Unity-DLL反编译学习
- Unity-反编译由IL生成的DLL文件
- Unity学习笔记(5) --- Unity的界面排版:AutoLayout详解——关于高度height的计算
- unity 中抗锯齿设置