I am working on a system of make the player cover in a wall(the system of cover is already done), so I have a wall that inside of that object it has 4 empty objects that are set in the 4 edges of the rectangle wall and these 4 empty objects have a box collider that are trigger and all is fine until I decide to scale the wall bigger or smaller, the 4 empty objects grow too and I want that when you scale it the empty objects change the position but not the scale. I want an easy idea with no use of script but if is not possible, with script is ok.
There’s no way to keep the original size without scripts when you change the parent scale at runtime. Calculate the original object scale (it’s initial scale * parent scale - the function Vector3.Scale does this multiplication), then anytime the parent scale changes, divide each original scale component (x, y, z) by its corresponding in the new parent scale.
private var orgScale: Vector3; // original child scale before parenting private var lastScale: Vector3; // last parent scale function Start () { lastScale = transform.parent.localScale; // calculate the original child scale (localScale * parentScale) orgScale = Vector3.Scale(transform.localScale, lastScale); } function Update () { var dadScale = transform.parent.localScale; if (dadScale != lastScale){ // if daddy changed scale... var newScale = orgScale; // calculate new child scale: newScale.x /= dadScale.x; newScale.y /= dadScale.y; newScale.z /= dadScale.z; transform.localScale = newScale; // set child scale at once lastScale = dadScale; // remember last parent scale } }
if (Size != Old_Size && SphereColider != null)
{
SphereColider.radius *= Old_Size / Size;
}
transform.localScale = new Vector3(Size, Size, Size);
Old_Size = Size;
important part is “*= Old_Size / Size;”