- Home /
vector 3 variable to have gameobject value editor time :D
Hey,
this is sort of tricky to explain. So I have this Teleport Script, that teleports player left or right. And I'm using vector 3 variable as destination point.
You can move around the vector variable with custom editor handles thing.
void OnSceneGUI()
{
//if (_target.teleportBoy)
_target.teleportPointLeft = Handles.PositionHandle(_target.teleportPointLeft, Quaternion.identity);
//if (_target.teleportRobot)
_target.teleportPointRight = Handles.PositionHandle(_target.teleportPointRight, Quaternion.identity);
}
Which is cool, you can use vector 3 variables as if they were Gameobject, and easily teleport player to custom destination (which is editable is editor mode) without using external gameobjects.
So what my problem is, when I create vector 3 variable its default value is 0,0,0. and I can initialize it to use transform.position from object it is attached to, so this vector 3 starts near the object teleport script was applied to. BUT initialization only happens after I run the game. and I want to set default value before the game runs, so when you add the script as component to gameobject, they are near this game object from the start.
So I need something like this
public Vector3 teleportPointLeft = new Vector3(gameObject.transform.position.x-30, gameObject.transform.position.y, 0);
to happen without running the game. And I have trouble wrapping my mind around this whole concept :D I know I'm missing some basic programming thing, but can't understand what.
Where are you setting the Vector3 variable? in a $$anonymous$$onoBehaviour
? if so, then just mock it with [ExecuteInEdit$$anonymous$$ode]
and set it somewhere in Awake or OnEnable - if you're setting it in an Editor
then use OnEnable
.
Your answer
![](https://koobas.hobune.stream/wayback/20220613135618im_/https://answers.unity.com/themes/thub/images/avi.jpg)