Skip to content

Instantly share code, notes, and snippets.

@maxattack
Created November 22, 2018 07:38
Show Gist options
  • Save maxattack/5ada9e4c1ee51f9a65b75e030fe1fcbb to your computer and use it in GitHub Desktop.
Save maxattack/5ada9e4c1ee51f9a65b75e030fe1fcbb to your computer and use it in GitHub Desktop.
ExecuteInEditMode Sample
using UnityEngine;
[ExecuteInEditMode]
public class AbsoluteScale : MonoBehaviour {
public Vector3 scale = new Vector3(1f, 1f, 1f);
#if UNITY_EDITOR
void Update () {
if (Application.isPlaying)
return;
if (transform.parent) {
var parentScale = transform.parent.lossyScale;
var relativeScale = new Vector3(
scale.x / parentScale.x,
scale.y / parentScale.y,
scale.z / parentScale.z
);
transform.localScale = relativeScale;
} else {
transform.localScale = scale;
}
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment