Reputation: 19
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;
}
}
Upvotes: 1
Views: 604
Reputation: 444
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.
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.
Upvotes: 1