简体   繁体   English

试图让相机在2D中自动滚动(不跟随播放器)

[英]Trying to get camera in unity 2D to automatically scroll (not follow the player)

I'm creating a 2D platformer and want the camera to automatically start scrolling as the level starts and not follow the player. 我正在创建一个2D平台游戏,并希望相机在关卡开始时自动开始滚动而不是跟随玩家。 If the player leaves the camera zone they will die (already have this sorted). 如果玩家离开相机区域,他们将死亡(已经将其排序)。 Just not that use to scritping cameras so any help would be much appreciated :) thanks 只是没有用于scritping相机,所以任何帮助将非常感谢:)谢谢

You can use the update function to change the position of the camera gradually: 您可以使用更新功能逐渐更改摄像机的位置:

private void Update()
{
    float step = 5;

    var cameraPosition = Camera.main.gameObject.transform.position;
    cameraPosition.x += step;
    Camera.main.gameObject.transform.position = cameraPosition;
}

You will want to change step to be something relevant to your game, taking into account the width of the scene and the time you want the movement to take. 您需要将step更改为与游戏相关的step ,同时考虑场景的宽度和您想要移动的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM