As the title suggests, I am looking to serialize on the Inspector a Vector3 that behaves just as the Transform's position Vector3:
- If you modify the position Vector3, the GameObject positions itself according to the World Position.
- If you move the GameObject on the scene by picking the handles, the GameObject moves, and the position Vector3 gets modified equal to the GameObject's position.
So, is there a way I can constrain a serialized Vector3, so if I modify it on the inspector I can change the GameObject's position, like this:
[ExecuteInEditMode]
public class LameExample : MonoBehaviour
{
public Vector3 transformPosition;
private void Update()
{
if(modifyingVectorOnInspector)
transform.position = transformPosition;
else if(gameObjectIsBeingMovedOnScene)
transformPosition = transform.position;
}
}
I've tried an approach using Selection.contains(gameObject), but that does not take into account if it is dragged by the handles.
Thanks in advance for your help.