This code tries to make a slider relative to a menu item’s position…
public void MakeSlider (Setting param, GameObject menuHolder) {
slider = new GameObject ("Slider");
if (openMenu.localised) {
slider.transform.parent = menuHolder;
slider.transform.localPosition = param.slider.pos + Delocalise (menuHolder.transform.position);
param.slider.bar.localised = true;
param.slider.hand.localised = true;
}
slider.transform.localRotation = Quaternion.Euler (param.slider.rot);
slider.transform.localScale = param.slider.scale;
//[...]
}
…using this custom function…
public Vector3 Delocalise (Vector3 pos) {
pos = new Vector3 (Camera.main.ScreenToWorldPoint(pos).x / Screen.width,
Camera.main.ScreenToWorldPoint(pos).y / Screen.height,
pos.z);
return pos;
}
…where menuHolder is an empty parent GameObject, itself a child of the empty menu parent GameObject. The menu applies a position to menuHolder, which in turn applies a position to a GUIText menu item. The idea is to have not a GUITexture, but two groups of animated GameObjects with Sprite Renderer components to make up the slider at runtime.
Everything seems to work perfectly except for the conversion from screen units to world units that would make the slider relative to the menu item. I’ve tried not dividing by screen width and height and the results are different, but still unsatisfactory.
It seems as though Delocalise is taking menuHolder’s local position instead of its global position like transform.position should.