Hi.
I got a problem with my Camera.
I have a main menu where I can choose one player among two of them. When I select a player it spawns the player in the game but as soon as the player spawns in the game and starts moving
The camera doesn’t follow the player it stays in the same position. Can someone help me?
This is my camera script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Camera_Script: MonoBehaviour
{
private Transform player;
private Vector3 temPos;
[SerializeField]
private float minX, maxX;
// Start is called before the first frame update
void Start()
{
player = GameObject.FindWithTag("Player").transform;
}
// Update is called once per frame
void LateUpdate()
{
if (!player)
return;
temPos = transform.position;
temPos.x = player.position.x;
if (temPos.x < minX)
{
temPos.x = minX;
}
if (temPos.x > maxX)
{
temPos.x = maxX;
}
transform.position = temPos;
}
}