你好,我可以帮助你翻译这个问题。

你正在尝试创建一个类似城市建造/实时战略游戏的摄像头,使用WASD键和鼠标在屏幕边缘移动。然而,最近你发现摄像头开始向下左角移动,并且无法使用键盘移动摄像头而不移动鼠标。

你的完整代码如下:

[SerializeField]
private float speed;
[SerializeField]
private int screenEdge;
private Vector2 _moveInput;
private Rigidbody2D _rb;

// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
    _rb = GetComponent<Rigidbody2D>();
}

// Update is called once per frame
void Update()
{
    _rb.linearVelocity = _moveInput.normalized * speed;
}

public void Move(InputAction.CallbackContext ctx)
{
    _moveInput = ctx.ReadValue<Vector2>();
}

public void EdgeMove(InputAction.CallbackContext ctx)
{
    if (ctx.ReadValue<Vector2>().y < screenEdge)
    {
        _moveInput.y = -1f;
    }
    else if (ctx.ReadValue<Vector2>().y > Screen.height - screenEdge)
    {
        _moveInput.y = +1f;
    }
    if (ctx.ReadValue<Vector2>().x < screenEdge)
    {
        _moveInput.x = -1f;
    }
    else if (ctx.ReadValue<Vector2>().x > Screen.width - screenEdge)
    {
        _moveInput.x = +1f;
    }
    if (ctx.ReadValue<Vector2>().y > screenEdge && ctx.ReadValue<Vector2>().y < Screen.height - screenEdge && ctx.ReadValue<Vector2>().x > screenEdge && ctx.ReadValue<Vector2>().x < Screen.width - screenEdge)
    {
        _moveInput.x = 0f;
        _moveInput.y = 0f;
    }
}

你的输入系统如下:

图片1
图片2

你不清楚为什么摄像头停止工作正确,因为没有其他脚本影响摄像头。你想知道为什么会这样,并且需要一些建议和解决方案。

答案:
最可能的原因是你的摄像头脚本与其他脚本或组件冲突了。例如,其他脚本可能正在修改摄像头的位置或速度。或者,可能是由于某个组件或设置导致摄像头的行为异常。

建议:
1. 检查其他脚本和组件是否影响摄像头。
2. 确保摄像头脚本是最新的。
3. 尝试禁用其他脚本或组件,看看是否可以正常工作。
4. 检查摄像头的设置,例如速度和边缘距离,看看是否有任何异常。
5. 如果问题仍然存在,请尝试重写摄像头脚本或使用其他方法来实现相同的功能。

希望这些建议可以帮助你解决问题!