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