【发布时间】:2014-05-27 09:32:35
【问题描述】:
我正在使用 Unity 制作一个简单的 2D 游戏,编写代码并不难,但我在移动 移动设备上的相机(在编辑器中它工作得很好!)。
这是移动相机的脚本(自定义平滑跟随脚本。它跟随玩家并且阻尼变量设置为 10)。
using UnityEngine;
using System.Collections;
public class SmoothFollow : MonoBehaviour {
public Transform target; // The target we are following
public float positionDamping;
private Vector3 deltaPos;
// Use this for initialization
void Start () {
deltaPos = new Vector3(-4f, 1f, 0f);
}
// Update is called once per frame
void Update () {
}
public void FixedUpdate () {
Vector3 targetPosition = target.position - (Vector3.forward * 10);
//transform.position = Vector3.MoveTowards(transform.position, targetPosition + deltaPos, positionDamping * Time.deltaTime);
Camera.main.transform.position = Vector3.Lerp(Camera.main.transform.position, targetPosition + deltaPos, positionDamping * Time.deltaTime);
}
}
如果有人的话,这是完整的项目 想试试(RAR archive, 10Mo)
ps:我在三星 Galaxy S3 (i9300) 上试用过
【问题讨论】: