赞
踩
首先说明一下,今天将的手动漫游方式需要借助Unity的手势插件: FingerGestures
具体插件如何使用,请看文章:
http://blog.csdn.net/qq_15267341/article/details/51878844?locationNum=1&fps=1
三步搞定手动漫游:
1 场景中建立一个相机
2 相机上挂一个角色控制器脚本
3 相机上挂如下代码脚本(shouDongManYou.cs)
最后调整相机的参数以确定相机的初始位置,调整角色控制器的Center、Radius、Height
public class shouDongManYou : MonoBehaviour {
private float a01; //a01和a02控制左右旋转
private float a02;
private float b01; //b01和b02控制上下旋转
private float b02;
// Use this for initialization
void Start () {
}
void Update()
{
}
public void jieshu() //退出漫游手动漫游时取消事件
{
FingerGestures.OnDragMove -= dragMove;
FingerGestures.OnFingerStationary -= onFingerStationary;
}
void OnEnable()
{
a01=a02 = transform.localEulerAngles.y;
b01=b02 = transform.localEulerAngles.x;
FingerGestures.OnDragMove += dragMove;
FingerGestures.OnFingerStationary += onFingerStationary;
}
// Update is called once per frame
Vector2 previousPos;
void dragMove(Vector2 fingerPos, Vector2 delta)
{
a01 += delta.x * 0.06f;
a02 = Mathf.Lerp(a02, a01, Time.deltaTime * 30f);
b01 += delta.y * 0.5f;
b02 = Mathf.Lerp(b02, b01, Time.deltaTime * 30f);
b02 = Mathf.Clamp(b02, -3, 3);
transform.rotation = Quaternion.Euler(b02, a02, transform.localEulerAngles.z);
}
void onFingerStationary(int fingerIndex, Vector2 fingerPos, float elapsedTime)
{
if (elapsedTime>0.5f)
{
GetComponent<CharacterController>().SimpleMove(transform.forward);
}
}
}
一定要注意墙和地板都要添加碰撞体
特别注意如下:
FR:海涛高软(QQ技术交流群:386476712)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。