1
NGUI 3 Support / Dual Sliders on the one game object
« on: July 31, 2014, 12:10:45 PM »
What I have is one game object with two sliders attached to it. I've wrote code that stops the thumbs from ever going over each other. So each slider shares the same background and foreground but is stopped when the met along the line. Should slider one move .3 along the length, slider two can move .7.
What I have is a cube where each face of it is controlled by one slider (I've 3 total with 2 sliders each for a total of 6 sliders). When the slider moves it moves the corresponding face. When the cubes face is moved, the centre point is recalculated and it simulates I'm pushing out a wall or something.
However, what I need is for this cube to have a value of 0 where ever these points meet based on the sliders values. Thus if I push out one cube face by .3, if I bring in my other slider would travel the rest of way and make my cube extremely skinny (on the x axis).
Code looks like this (only doing X just now):
Then in my update method I'm doing the following to the cube:
I'm also passing the values along via this code:
Can someone please tell me where my math is wrong on this as I can't seem to get it working correctly
What I have is a cube where each face of it is controlled by one slider (I've 3 total with 2 sliders each for a total of 6 sliders). When the slider moves it moves the corresponding face. When the cubes face is moved, the centre point is recalculated and it simulates I'm pushing out a wall or something.
However, what I need is for this cube to have a value of 0 where ever these points meet based on the sliders values. Thus if I push out one cube face by .3, if I bring in my other slider would travel the rest of way and make my cube extremely skinny (on the x axis).
Code looks like this (only doing X just now):
- private void SliceXPos()
- {
- xPVal = xsliderTwo.value * maxX ;
- }
- private void SliceXNeg()
- {
- xNVal = xsliderOne.value * -maxX;
- }
Then in my update method I'm doing the following to the cube:
- sliceBox.transform.localPosition = new Vector3((xPVal - xNVal) / 2 + xNVal, (yPVal - yNVal) / 2 + yNVal, (zPVal - zNVal) / 2 + zNVal);
I'm also passing the values along via this code:
- xSliders = xObject.GetComponents<UISlider>();
- if (xSliders == null || xSliders.Length < 2)
- {
- this.enabled = false;
- Debug.LogWarning("Script Requires 2 UISliders");
- }
- else
- {
- xsliderOne = xSliders[0];
- xsliderTwo = xSliders[1];
- EventDelegate.Add(xsliderOne.onChange, Clamp);
- EventDelegate.Add(xsliderTwo.onChange, Clamp);
- EventDelegate.Add(xsliderOne.onChange, SliceXNeg);
- EventDelegate.Add(xsliderTwo.onChange, SliceXPos);
- }
Can someone please tell me where my math is wrong on this as I can't seem to get it working correctly