简体   繁体   English

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

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

I made a script for my camera for following the player.When I play the game, game view goes white, even if on scene view all is fine我为我的相机制作了一个脚本来跟随玩家。当我玩游戏时,游戏视图变白,即使在场景视图中一切都很好

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;
   
    }
}

The problem might be that the player is blocking the camera (because the camera is inside the player).问题可能是玩家挡住了相机(因为相机在玩家内部)。 Try adding some offset by adding a Vector3 as a variable and adding it on to the transform.position.尝试通过将 Vector3 添加为变量并将其添加到 transform.position 来添加一些偏移量。

The offset could be used so that the camera is in front of the player, or in a third person angle.可以使用偏移量,使相机位于玩家面前,或以第三人称视角。

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;
        
    }
}

Hope this helps.希望这可以帮助。

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

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