Support => NGUI 3 Support => Topic started by: pretender on April 27, 2014, 04:55:12 AM
Title: Getting current position in Slider?
Post by: pretender on April 27, 2014, 04:55:12 AM
Hi!
I have a level progress bar with UISlider setup. As time progresses (level) slider moves to the end, I want to be able to mark certain points on the slider, for example sections of the level that are reached. In order to do this I need position of the right edge of the slider bar, then I should be able to instantiate a sprite over slider to mark that position.
Any ideas how to do it? Thanks!
Title: Re: Getting current position in Slider?
Post by: Sahkan on April 27, 2014, 10:23:09 AM
Make a new script, put this code into it ( In this case the file named : MyTestScript_1 ) :
usingUnityEngine;
usingSystem.Collections;
publicclass MyTestScript_1 : MonoBehaviour {
public UISlider slider_1 ;
void Update ()
{
print (slider_1.sliderValue);
}
}
Drag that script into the Slider object .
Drag the slider object from the hierarchy tab to the slider_1 value which shows in the Inspector (Because it declared as public ) .
Play the scene and it will print the value of it while you play in it every frame .
Title: Re: Getting current position in Slider?
Post by: pretender on April 27, 2014, 10:30:17 AM
Thanks for looking into this although i dont need a value of slider but the position of of a point that is on the right side of the slider (uisprite that is moving) that i can use to instantiate another sprite to mark position on the slider.
Title: Re: Getting current position in Slider?
Post by: Sahkan on April 27, 2014, 11:02:47 AM
I just wanna make sure we are on the same page .
Do you mean this sprite ? (http://i1148.photobucket.com/albums/o568/Sahkan/SpritePosition_zps05e12ca2.jpg) (http://i1148.photobucket.com/albums/o568/Sahkan/HierarchyPanel_Position_zps49f7e195.jpg)
Title: Re: Getting current position in Slider?
Post by: Sahkan on April 27, 2014, 11:13:46 AM
Because if so, all you need to do is :
1.Make a new script .
2.Attach it to the "Thumb" object ( Which is holding that sprite ) .
3.Open this script and put into the Update() function this line : print (transform.position); This line however will print the values with only one digit after the decimal point, If you want it to be more precise you should use these three lines : print ("X position : "+transform.position.x); print ("Y position : "+transform.position.y); print ("Z position : "+transform.position.z);
Title: Re: Getting current position in Slider?
Post by: pretender on April 27, 2014, 11:54:53 AM
I dont have thum since its progress bar, it is the sprite which is moving
Title: Re: Getting current position in Slider?
Post by: Sahkan on April 27, 2014, 12:22:35 PM
But some object has to have the sprite on it, it's not just sitting there...
Title: Re: Getting current position in Slider?
Post by: pretender on April 27, 2014, 11:46:46 PM
If you click on any sprite in edit view you will notice green handles, i need that in run time
Title: Re: Getting current position in Slider?
Post by: ArenMook on April 28, 2014, 12:15:41 AM
The thumb doesn't need to be visible. You can simply create a plain game object and set that to be the thumb. You can then retrieve its position like you would with any game object.
Title: Re: Getting current position in Slider?
Post by: pretender on April 28, 2014, 12:19:54 AM
Ok i will try that, but anyhow i would like to know how you draw handles on edges of the sprite, how do you get that position?
Title: Re: Getting current position in Slider?
Post by: pretender on April 28, 2014, 02:14:11 AM
ok thanks to both of you, i thought it might involve something else but this was simple and elegant