- Home /
How do I draw lines in a Rect
Hello,
I need to draw lines in a Panel (with Unity 4.6/5 GUI) to simulate stocks market values as they're changing. How do I do that? The game will be on Facebook and for Android (with varying screen aspects of course) so every GUI element that I did is relative to its parent canvas rather than absolute dimensions (is this wrong)?
What I've tried to do up to now was to get the panel's (where I draw the lines) real-world min and max Xs and Ys to know what my borders are and then it's just mathematics and the use of LineRenderer to make it happen. Unfortunately All I can get via:
float minX = Camera.main.ScreenToWorldPoint(graphBG.offsetMin).x;
float minY = Camera.main.ScreenToWorldPoint(graphBG.offsetMin).y;
float maxX = Camera.main.ScreenToWorldPoint(graphBG.offsetMax).x;
float maxY = Camera.main.ScreenToWorldPoint(graphBG.offsetMax).y;
Is the canvas that hold all the other canvases in the game (they're all his children). Also that Master Canvas is set to be "Screen Space - Camera" otherwise it just block every other render in Screen Space - Overlay.
So what can I do?
I don't mind paying for a plug-in to do it for me if there's one out there.
Thanks ahead, Shay.
Answer by omatase · May 06, 2015 at 01:09 AM
I did something like this where I showed a character's experience to next level in a bar. I used the slider control that comes with the new Unity UI and just deactivated the handle game object that gets nested within. It worked pretty well. Just set the "value" to a number between 0 and 1.
public Slider CharacterXpSlider = null;
CharacterXpSlider.value = (float)newValue / maximumValue;
Seems legit but how can I make several dynamic sliders on the fly? The Graphs are made of several sagements how can I know where each sagement starts and ends?
I just use Instantiate for something like that. This page in the Unity manual talks about that. http://docs.unity3d.com/$$anonymous$$anual/HOWTO-UICreateFromScripting.html
Here's an example
public GameObject YourPrefabType = null;
...
GameObject sliderInstance = (GameObject)Instantiate(YourPrefabType);
Your answer
Follow this Question
Related Questions
Line Renderer in GUI 0 Answers
Drawing lines from mouse position 2 Answers
Gameobject is drawing a line render,when it's not supposed to ! 0 Answers
uGUI Button size based on text size 1 Answer
Draw line in runtime 1 Answer