Unity C#摄像头出现问题,摄像头变白
我为我的相机制作了一个脚本,以便跟踪玩家。当我玩游戏时,游戏视图会变为白色,即使在场景视图中一切正常Unity C#摄像头出现问题,摄像头变白,c#,unity3d,camera,C#,Unity3d,Camera,我为我的相机制作了一个脚本,以便跟踪玩家。当我玩游戏时,游戏视图会变为白色,即使在场景视图中一切正常 using System.Collections; using System.Collections.Generic; using UnityEngine; public class FollowPlayer : MonoBehaviour { public Transform player; public Vector3 playerpos; // Start is
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;
}
}
问题可能是播放器挡住了摄像头(因为摄像头在播放器内部)。尝试通过添加矢量3作为变量并将其添加到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;
}
}
希望这有帮助。你确定问题出在脚本上吗?你是否尝试过禁用它并进入播放模式?是的,我尝试过,一切都很好。它渲染任何东西,我尝试过将相机作为孩子连接到播放器上,它工作正常,但我只想跟随x轴谢谢大家!解决了!这个网站太棒了