- Home /
UI parenting and sizing problem
So I currently have a table set up with 9 User Interfaces (UI) laid across it. You can pick up the UI (they are set up as an empty game object with the child as the UI canvas) and once you pick up and hold the UI (grabbed), you can press either the right or left of the thumb pad to scale up or down the canvas. Once you release the UI (ungrab) the canvas becomes parented to the suit the user is wearing. When I try to re-grab the UI and scale it, this does not work. I am wondering why I cannot scale a second time after releasing the UI.
private void DebugLogger(uint index, string action, GameObject target)
{
VRTK_Logger.Info("Controller on index '" + index + "' is " + action + " an object named " + target.name);
}
private void DoInteractGrab(object sender, ObjectInteractEventArgs e)
{
if (e.target)
{
DebugLogger(VRTK_ControllerReference.GetRealIndex(e.controllerReference), "GRABBING", e.target);
//sets grab on condition to true
grabOn = true;
//identifies the grabbed object as the gameobject grabObject
grabObject = e.target;
}
}
private void DoInteractUngrab(object sender, ObjectInteractEventArgs e)
{
if (e.target)
{
DebugLogger(VRTK_ControllerReference.GetRealIndex(e.controllerReference), "NO LONGER GRABBING", e.target);
//sets grabbed object as child of the suit after letting go
e.target.transform.parent = Suit.transform;
//turns grab on condition to false
grabOn = false;
}
}
private void DebugLogger(uint index, string button, string action, ControllerInteractionEventArgs e)
{
VRTK_Logger.Info("Controller on index '" + index + "' " + button + " has been " + action
+ " with a pressure of " + e.buttonPressure + " / trackpad axis at: " + e.touchpadAxis + " (" + e.touchpadAngle + " degrees)");
}
private void DoTouchpadAxisChanged(object sender, ControllerInteractionEventArgs e)
{
DebugLogger(VRTK_ControllerReference.GetRealIndex(e.controllerReference), "TOUCHPAD", "axis changed", e);
float angle = e.touchpadAngle;
float resize = 1.1f;
//if touching the right side of the thump pad, will size up by 1.1
if (angle > 0 && angle <= 180) {
resize = 1.1f;
}
//if touching the left side of the thumb pad, will size down -1.1
if (angle > 180 && angle <= 360) {
resize = -1.1f;
}
print ("game object is" + grabObject.name);
print (angle);
if (grabOn == true) {
grabObject.transform.localScale += new Vector3(resize*0.0001f,resize*0.0001f,resize*0.0001f);
}
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612125643im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Scale UI element On One Side 0 Answers
Unity UI World Canvas Scale Reason 0 Answers
Multiple Cars not working 1 Answer
Scaling RectTransform to fit screen size in code 1 Answer
Distribute terrain in zones 3 Answers