这是一款 2D 平台游戏。
当玩家跳跃时,我不希望相机沿 Y 轴向上移动。我只希望它在玩家移动到屏幕上部时移动,以便它可以向上滚动到垂直平台和梯子。
有谁知道在代码和 Unity 编辑器中输入什么以便可以完成?
这是到目前为止我在相机脚本中的代码。
public class CameraControl : MonoBehaviour {
public GameObject target;
public float followAhead;
public float smoothing;
private Vector3 targetPosition;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
targetPosition = new Vector3 (target.transform.position.x, transform.position.y, transform.position.z);
if (target.transform.localScale.x > 0f) {
targetPosition = new Vector3 (targetPosition.x + followAhead, targetPosition.y, targetPosition.z);
} else {
targetPosition = new Vector3 (targetPosition.x - followAhead, targetPosition.y, targetPosition.z);
}
transform.position = Vector3.Lerp (transform.position, targetPosition, smoothing * Time.deltaTime);
}
}