I actually thought about not putting this cause like it actually matters less if you are in unity 2020 or newer, but since the course is written in unity 2018…
Searching for the camera in update is supposedly kind of expensive. I’m sure he will make this better later in the course, but for now at least I’m caching a reference to the camera just for a bit of optimization.
@Brian_Trotter is the above correct? if so, does the caching help? I don’t actually know why its a problem i just remember reading it was in a forum or on a tutorial a while ago. my assumption is that its just generally resource intensive to look for camera components but its just a guess.
using UnityEngine;
namespace RPG.Core
{
public class CameraFacing : MonoBehaviour
{
Camera _camera;
private void Awake()
{
_camera = Camera.main;
}
void Update()
{
transform.forward = _camera.transform.forward;
}
}