Ok Im using unity 4.6 and have a UI slider visible to the player. Beside the slider I have a UI Text which is showing a String of 500. The Slider head is at the right hand side (500) and can be slid left towards what I want to be 0.
I have the following code in place but when i slide the slider the Text value starts at 500 and automatically changes to 0.99 and moves the whole way down to 0 on the left hand side. If i was to slide it back up to the right hand side it has a value of 1.
public class SliderUITextUpdate : MonoBehaviour {
string sliderTextString = "500";
public Text sliderText;
public void textUpdate(float textUpdateNumber)
{
sliderTextString = textUpdateNumber.ToString ();
sliderText.text = sliderTextString;
}
}
This script is attached to a Manager object (just an empty gameobject) and then the text game object is applied in the inspector.
On the slider object I am using the OnValueChanged() ability in the inspector. To which I have attached the Manager gameobject and set it to use SliderUITexture.textUpdate
Any help would be great thanks !
public class SliderUITextUpdate : MonoBehaviour {
string sliderTextString = "500";
public Text sliderText;
public Slider mainSlider;
void Awake(){
mainSlider.maxValue = 500;
}
public void textUpdate(float textUpdateNumber)
{
sliderTextString = textUpdateNumber.ToString ();
sliderText.text = sliderTextString;
}
}
get the referece for that slider in inspector
Related
i am new to wpf and i need to open up a pop up a new window on grid row click which contains lots of data and controls on it.i am confused with the correct approach. i am using mvvm pattern.should i make a window control or user control or something else. and how to open that pop up inside a function. please help with example
If I need to display a new Window in my MVVM-Application I use the following approach:
At first I have an interface with a method to show the new dialog:
internal interface IDialogManager
{
void DisplayData(object data);
}
And an implementation like:
internal class DialogManager : IDialogManager
{
public void DisplayData(object data)
{
LotOfDataViewModel lotOfDataViewModel = new LotOfDataViewModel(data);
LotOfDataView lotOfDataView = new LotOfDataView
{
DataContext = lotOfDataViewModel
};
lotOfDataView.ShowDialog();
}
}
LotOfDataViewModel and LotOfDataView are the new Dialog where you want to show your data.
In your actual ViewModel you introduce a new property like:
private IDialogManager dialogManager;
private IDialogManager DialogManager
{
get { return dialogManager ?? (dialogManager = new DialogManager()); }
}
And the you can show your large data with:
DialogManager.DisplayData(myData);
I have just started using the Mixed Reality Toolkit (former Holotoolkit) and I am trying to use a slider.
So I made a scene with a 3DTextPrefab, a Button and a Slider.
I wrote a script and attach it to the 3DTextPrefab. This script is
public class Clicker : MonoBehaviour {
public GameObject ObjectToShow;
public float waitTime;
private void Awake()
{
ObjectToShow.SetActive(false);
}
public void Click()
{
TextMesh tm = ObjectToShow.GetComponent("TextMesh") as TextMesh;
tm.text = "Hello with parameter" + waitTime;
ObjectToShow.SetActive(true);
StartCoroutine(HideAfterTimeout());
}
public void setWaitTime(float t)
{
waitTime = t;
}
IEnumerator HideAfterTimeout()
{
// yield return new WaitForSeconds(0.1f);
yield return new WaitForSeconds(waitTime);
ObjectToShow.SetActive(false);
}
}
In the button, there is the "Interactive" script (by default), so I added the 3dTextPrefab as an object to the OnSelectedEvents list and selected its Click function.
Doing this every time I click on the button, it calls the click function of the Prefab script. So far so goo.
I tried to do something similar with the slider so I added the prefab as an object to the Slider Gesture Control script's OnUpdateEvent and selected its setWaitTime function.
My problem is, the setWaitTime function has a parameter and I can see that in the inspector. This parameter has to be the actual value of the slider.
How do you get the actual value of the slider to put it there?
The slider should have a value property that you can read from. Add the slider to your script, assign your slider to the slot in the inspector and then you can access the value property from inside of your script.
I have made a quiz game and I want to be able to show an image right after a user answered correctly. The problem is i have a bunch of questions and images that it becomes tedious to set visibility for each and every image. How do I optimize this procedure. I was thinking of maybe placing the images in an array but i don't really know if its possible or to make it show up in the place that i want.
As I understood, the problem is that you have N images and you iterate each time over the whole set to set the visibility. In your case I would (as you suggested) create an array of those images and few helper functions. Some basic example:
private var imageVector: Vector.<DisplayObject>; // this vector holds all your images
private var currentImage: DisplayObject; // the image that is shown currently
private function createAndFillImages():void {
imageVector = new Vector.<DisplayObject>();
imageVector.push(image1);
imageVector.push(image2);
//... etc. it depends on how your images are presented.
}
private function onAnswerGiven():void {
const img: DisplayObject = ... // pick the right image here
showImage(img)
}
private function showImage(img: DisplayObject):void {
if (currentImage != null) currentImage.visible = false;
currentImage = img;
// ... do the positioning here
currentImage.visible = true;
}
I think, that something has broken in cn1 painting model. Could someone review if this is a bug or am I doing something incorrectly?
I would like to archive the following:
On a form is a label, which text is refreshed with UITimer with 1 second interval. For example:
To indicate some activity on form is used form.setGlassPane(..) to paint a shadow above the form. The problem is, that on label text update label is repainted, but glasspane is not repainted, that is the shadow is not painted on the label:
Test code:
final Form form = new Form("Welcome", new BoxLayout(BoxLayout.Y_AXIS));
final Label label = new Label("..");
Button button = new Button("Show Shade");
form.addComponent(label);
form.addComponent(button);
button.addActionListener((e) -> {
form.setGlassPane(new Painter() {
public void paint(Graphics g, Rectangle rect) {
int wasAlpha = g.getAlpha();
g.setAlpha(50);
g.setColor(0x101010);
g.fillRect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
g.setAlpha(wasAlpha);
}
});
});
new UITimer(() -> {
label.setText(new Date().toString());
}).schedule(1000, true, form);
form.show();
This seems to be due to a fix for issue 1680 a while back. I reopened the issue, we'll need to figure out why this failed.
I am trying to display a custom dialog box multiple times using the following code:
TestWindow newTestWindow = new TestWindow(test);
newTestWindow.Owner = this;
newTestWindow.ShowDialog();
And I get the following exception when running the code above for the 2nd time:
Specified element is already the logical child of another element. Disconnect it first.
Chances are you are trying to display the same element in both dialogs (maybe the test parameter)? You would need to disconnect the element from the dialog when it's closed, so that it can be used in any subsequent dialogs.
Works fine for me:
public partial class MainWindow : Window
{
private Test _newTestWindow;
public MainWindow()
{
InitializeComponent();
Loaded += new RoutedEventHandler(OnLoaded);
}
private void OnLoaded( object sender, RoutedEventArgs e )
{
_newTestWindow = new Test { Owner = this };
_newTestWindow.ShowDialog();
_newTestWindow = new Test { Owner = this };
_newTestWindow.ShowDialog();
}
}