Accessing the Transform/TransformAccess
should be done as few times as possible for performance reasons. Starting with Unity 2021.3.11f1, instead of setting localPosition
and localRotation
sequentially, you should use SetLocalPositionAndRotation()
method.
using UnityEngine;
class Camera : MonoBehaviour
{
void Update()
{
transform.localPosition = new Vector3(0.0f, 1.0f, 0.0f);
transform.localRotation = transform.localRotation;
}
}
Fix assignment:
using UnityEngine;
class Camera : MonoBehaviour
{
void Update()
{
transform.SetLocalPositionAndRotation(new Vector3(0.0f, 1.0f, 0.0f), transform.localRotation);
}
}
A code fix is offered for this diagnostic to automatically apply this change.