C# Unity 5-编辑camera2DFollow脚本
我使用的是Unity 5附带的标准C# Unity 5-编辑camera2DFollow脚本,c#,unity3d,unity5,C#,Unity3d,Unity5,我使用的是Unity 5附带的标准camera2DFollow脚本。但是我对相机的位置有问题。我旋转了我的主摄像机,现在看起来像这样 你看,我的播放器在屏幕的顶部而不是中间 这是C#中为没有脚本的人提供的默认脚本 using System; using UnityEngine; namespace UnityStandardAssets._2D { public class Camera2DFollow : MonoBehaviour { public Transform targe
camera2DFollow
脚本。但是我对相机的位置有问题。我旋转了我的主摄像机,现在看起来像这样
你看,我的播放器在屏幕的顶部而不是中间
这是C#中为没有脚本的人提供的默认脚本
using System;
using UnityEngine;
namespace UnityStandardAssets._2D
{
public class Camera2DFollow : MonoBehaviour
{
public Transform target;
public float damping = 1;
public float lookAheadFactor = 3;
public float lookAheadReturnSpeed = 0.5f;
public float lookAheadMoveThreshold = 0.1f;
private float m_OffsetZ;
private Vector3 m_LastTargetPosition;
private Vector3 m_CurrentVelocity;
private Vector3 m_LookAheadPos;
// Use this for initialization
private void Start()
{
m_LastTargetPosition = target.position;
m_OffsetZ = (transform.position - target.position).z;
transform.parent = null;
}
// Update is called once per frame
private void Update()
{
// only update lookahead pos if accelerating or changed direction
float xMoveDelta = (target.position - m_LastTargetPosition).x;
bool updateLookAheadTarget = Mathf.Abs(xMoveDelta) > lookAheadMoveThreshold;
if (updateLookAheadTarget)
{
m_LookAheadPos = lookAheadFactor*Vector3.right*Mathf.Sign(xMoveDelta);
}
else
{
m_LookAheadPos = Vector3.MoveTowards(m_LookAheadPos, Vector3.zero, Time.deltaTime*lookAheadReturnSpeed);
}
Vector3 aheadTargetPos = target.position + m_LookAheadPos + Vector3.forward*m_OffsetZ;
Vector3 newPos = Vector3.SmoothDamp(transform.position, aheadTargetPos, ref m_CurrentVelocity, damping);
transform.position = newPos;
m_LastTargetPosition = target.position;
}
}
}
我想将Y更改为当前位置的a+3。所以如果我的相机在Y 2上,那么就把它放在Y 5上。(这使得玩家在中间而不是在顶部)。< /P>
谢谢你的帮助 您可以通过在每帧末尾的摄影机位置上添加3来完成此操作,但我建议不要这样做 我要做的是创建一个空对象,将其命名为“PlayerCameraCenter”,并使玩家成为该对象的父对象;然后将相机中心放置在相对于播放器的任意位置,如y=3,并使相机跟随此对象而不是播放器
这样,您就可以通过编辑器轻松更改相机的位置,而无需修改代码。谢谢!没想到这个!我对团结有点陌生