- Home /
Link x,y,z values in Vector3 field
Hi,
I have a custom editor window where I display the selected GO’s localscale (like in the Transform component). The user can change its scale by typing his own values or sliding over it.
What I’d like to do is link the 3 fields, so that when changing one of the Vector3’s values, the 2 others are modified accordingly. Another way to say it is that the GO would be homotheticaly transformed, its aspect ratio would be preserved.
An example : let’s consider a GO having a scale of (2, 2, 1). If the user doubles the x value, I want the y and z value doubled too, so the resulting vector becomes (4, 4, 2). Without having to manually type them.
Thanx in advance
Answer by Razputin · May 10, 2021 at 02:18 PM
I believe you want to use this method https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnValidate.html
I suppose if X and Y are always going to be the same and Z is X / 2 you could just do...
void OnValidate()
{
someVector3 = new Vector3(someVector3.x, someVector3.x, someVector3.x/2);
}
then just only allow them to modify x.
Sorry for replying so late, been offline for several months. Your idea seems interesting, I will dig it. Thanx
Your answer
Follow this Question
Related Questions
Using a gameObject as Raycast origin position? 2 Answers
Use Rect.Contains to define an area on touchScreens 1 Answer
I need help with Jump animations 0 Answers
Sensitivity on Android Input.acceleration 2 Answers
Problem with Vector3 position. 1 Answer