- Home /
Update Scene on IndexChanged in Dropdown list
Hello, I'm creating a 3d visualization of different measures (defined by various equations) in Unity. The model which I'm coding is tetrahedron. I visualize points inside it using function OnDrawGizmos(), which I know is a part of Update() function of scene. The problem is that I don't know how to update Gizmos color when I'm choosing different option from a dropdown (dropdown contains options of various measures and based on that measures and their equations I should visualize gizmos in different colors giving them color scale). When I start the scene everything is fine, I see gizmos in blue color, which I defined at the Start() function, but don't know how to assign different colors to gizmos, when changing option from dropdown. Any help would be appreciated.
Answer by Harinezumi · Jun 18, 2018 at 07:37 AM
Create a public function on your script, for example OnDropdownChanged(int value)
. In this function set to a Color
member variable (e.g. gizmosColor
) the color you want, for example in a switch-case
. Then in your OnDrawGizmos()
call Gizmos.color = gizmosColor;
. Finally, in the Editor link the OnValueChanged(int)
event of the dropdown to this function.
Basically, the UI will call this function, you store the selected option's color, and set the color when you need it (this is needed because Gizmos.color
is static, so other scripts might change Gizmos.color
before this script's OnDrawGizmos()
gets called).
Thank you very much, I did as you said and it worked :)
Your answer
Follow this Question
Related Questions
I can't click to an UI button. 3 Answers
Update from Unity 4 to Unity 5.4.1 Scene Crashing 2 Answers
I did something and now my scene looks weird 1 Answer
Camera.main.pixel incorrectly return scene view's size in OnDrawGizmos 0 Answers
Use A button to set a color using playerprefs in a different scene? 2 Answers