Unity C#相机出现问题,相机变白



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

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;

}
}

希望这能有所帮助。

最新更新