繁体   English   中英

Unity C# 摄像头问题,摄像头变白

[英]Unity C# problem with camera, camera goes white

我为我的相机制作了一个脚本来跟随玩家。当我玩游戏时,游戏视图变白,即使在场景视图中一切都很好

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FollowPlayer : MonoBehaviour
{

    public Transform player;
    public Vector3 playerpos;
    // Start is called before the first frame update
    void Start()
    {
    
    }

    // Update is called once per frame
    void Update()
    {

        playerpos.x = player.position.x;

        transform.position = playerpos;
   
    }
}

问题可能是玩家挡住了相机(因为相机在玩家内部)。 尝试通过将 Vector3 添加为变量并将其添加到 transform.position 来添加一些偏移量。

可以使用偏移量,使相机位于玩家面前,或以第三人称视角。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FollowPlayer : MonoBehaviour
{

    public Transform player;
    public Vector3 playerpos;
    public Vector3 offset;
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {

        playerpos.x = player.position.x;
        transform.position = playerpos + offset;
        
    }
}

希望这可以帮助。

暂无
暂无

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

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