This is my code
using UnityEngine;
public class CompensarCamara : MonoBehaviour
{
public Transform faceTransform;
public float rotationSpeed = 10.0f;
void Update()
{
// Rotar el canvas para que mire hacia la cámara
transform.LookAt(faceTransform);
// Obtener la rotación actual del canvas
Quaternion currentRotation = transform.rotation;
// Obtener la rotación horizontal de la cara
float faceRotationY = faceTransform.rotation.eulerAngles.y;
// Calcular la rotación de compensación
Quaternion compensationRotation = Quaternion.Euler(0.0f, -faceRotationY, 0.0f);
// Rotar el canvas en la dirección contraria a la rotación de la cara
transform.rotation = currentRotation * compensationRotation;
}
}
It is assigned to a canvas and what I want it to do is:
- Make the canvas always look at the camera
- Gimbal effect so that if the player rotates the camera the canvas doesn´t
The problem: It does the second thing but not the first one. It throws this error:
UnassignedReferenceException: The variable faceTransform of CompensarCamara has not been assigned.
You probably need to assign the faceTransform variable of the CompensarCamara script in the inspector.
Here is an image of the canvas in the inspector:

It is obiously assigned or the gimbal effect would not work, any ideas what is happening here?