Reputation: 1
I am a beginner developer who is new to Unity. I have completed most of the basic code and now I am trying to write code related to the camera. I wrote the code as below and put the player in the method value and when I press the play button, the ground objects including the player are visible for a moment and then all objects except the UI are invisible. What is the problem with the code below? When I click the Scence tab, the camera is on the player, but the player or other objects are not visible in the Game tab.
Can someone help me?
using UnityEngine;
public class CameraFollow : MonoBehaviour {
public Transform target;
Vector3 offset = new Vector3(0, 5, -10);
void LateUpdate()
{
if (target == null)
{
return;
}
Vector3 desiredPosition = target.position + offset;
Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
transform.position = smoothedPosition;
}
}
Upvotes: 0
Views: 28