I have a field called “centerPoint” which stores a the transform of a “point placer” object. I want centerPoint to be able to be changed in the inspector by dragging the “point placer” object into the inspector, but I also want centerPoint to “default” to the objects own transform. Essentially, I want to do this.
public abstract class Enemy : MonoBehaviour {
public Transform centerPoint = transform;
}
But then, as expected, I get this error:
Assets/scripts/MonoBehaviors/Characters/Enemy.cs(11,40): error CS0236: A field initializer cannot reference the nonstatic field, method, or property `UnityEngine.Component.transform’
Obviously, this is happening because the value of “transform” will change during runtime.
Is there any way that I can get around this while still showing it in the inspector?