Author Topic: Dual Sliders on the one game object  (Read 2335 times)

NineTails

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
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):

  1.         private void SliceXPos()
  2.         {
  3.                 xPVal =  xsliderTwo.value * maxX ;
  4.         }
  5.  
  6.         private void SliceXNeg()
  7.         {
  8.                 xNVal = xsliderOne.value * -maxX;
  9.         }

Then in my update method I'm doing the following to the cube:
  1. sliceBox.transform.localScale = new Vector3(xPVal - xNVal, yPVal - yNVal, zPVal - zNVal);
  2.                         sliceBox.transform.localPosition = new Vector3((xPVal - xNVal) / 2 + xNVal, (yPVal - yNVal) / 2 + yNVal, (zPVal - zNVal) / 2 + zNVal);
  3.  

I'm also passing the values along via this code:

  1.         xSliders = xObject.GetComponents<UISlider>();
  2.                 if (xSliders == null || xSliders.Length < 2)
  3.                 {
  4.                         this.enabled = false;
  5.                         Debug.LogWarning("Script Requires 2 UISliders");
  6.                 }
  7.                 else
  8.                 {
  9.                         xsliderOne = xSliders[0];
  10.                         xsliderTwo = xSliders[1];
  11.  
  12.                         EventDelegate.Add(xsliderOne.onChange, Clamp);
  13.                         EventDelegate.Add(xsliderTwo.onChange, Clamp);
  14.  
  15.                         EventDelegate.Add(xsliderOne.onChange, SliceXNeg);
  16.                         EventDelegate.Add(xsliderTwo.onChange, SliceXPos);
  17.                 }

Can someone please tell me where my math is wrong on this as I can't seem to get it working correctly

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Dual Sliders on the one game object
« Reply #1 on: July 31, 2014, 12:36:32 PM »
First, I don't understand what you're trying to do with two sliders on the same object.

Second, I'm going to guess that you are still using NGUI 2 based on your code that adjusts transform scale. Is this correct?