簡體   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