Following camera in Unity

Viewed 10

I want to make the camera to follow the moving character, so I made a script FollowCamera like this.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FollowCamera : MonoBehaviour
{
    public Transform player; 

    // Start is called before the first frame update
    void Start()
    {
        // transform.position = player.transform.position; 
    }

    // Update is called once per frame
    void Update()
    {
        transform.position = player.position; 
    }
}

And I applied it to the main camera. Image1

I run the program then the the simulator comes weird. Everything disappeared except initial background. Image2

Can someone tell me what is the problem and why this happened?

0 Answers
Related