Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 仅将相机移动到某个位置_C#_Unity3d_Camera - Fatal编程技术网

C# 仅将相机移动到某个位置

C# 仅将相机移动到某个位置,c#,unity3d,camera,C#,Unity3d,Camera,你能看到这个gif中的蓝色区域吗?我想在玩家向左移动时挡住相机,以免看到蓝色区域。这是我用来移动相机的代码: 公共类配置:单行为{ Vector3 hit_position = Vector3.zero; Vector3 current_position = Vector3.zero; Vector3 camera_position = Vector3.zero; float z = 0.0f; public static bool bDedoNoHud; void Update() {

你能看到这个gif中的蓝色区域吗?我想在玩家向左移动时挡住相机,以免看到蓝色区域。这是我用来移动相机的代码:

公共类配置:单行为{

Vector3 hit_position = Vector3.zero;
Vector3 current_position = Vector3.zero;
Vector3 camera_position = Vector3.zero;
float z = 0.0f;
public static bool bDedoNoHud;

void Update()
{
    if (Input.GetMouseButtonDown(0))
    {
        hit_position = Input.mousePosition;
        camera_position = transform.position;

    }
    if (Input.GetMouseButton(0))
    {
        current_position = Input.mousePosition;
        LeftMouseDrag();
    }
    Debug.Log("bDedoNoHud" + bDedoNoHud);
}

void LeftMouseDrag()
{
    if (!bDedoNoHud)
    {
        // From the Unity3D docs: "The z position is in world units from the camera."  In my case I'm using the y-axis as height
        // with my camera facing back down the y-axis.  You can ignore this when the camera is orthograhic.
        current_position.z = hit_position.z = camera_position.y;

        // Get direction of movement.  (Note: Don't normalize, the magnitude of change is going to be Vector3.Distance(current_position-hit_position)
        // anyways.  
        Vector3 direction = Camera.main.ScreenToWorldPoint(current_position) - Camera.main.ScreenToWorldPoint(hit_position);

        // Invert direction to that terrain appears to move with the mouse.
        direction = direction * -1;

        Vector3 position = camera_position + direction;

        transform.position = position;
    }           
}

}你的意思是设置边界


把它放到更新()中。

你是说设置边界

将其放入更新()中