- Home /
Drawing a Line When clicking a checkbox?
Hi Everyone, I am new to Unity and trying to figure out how to create a line when clicking a button or checking a checkbox. So, for instance, let's say that I am creating a map. Now, I would like to check a checkbox or a radio button which creates a path (line) from point A to point B. Hope this clarifies hat I am looking for. I really would appreciate if someone would walk me through this. Thank you!
Answer by joemane22 · Mar 13, 2020 at 10:22 PM
You would want to use LineRenderer for this
https://docs.unity3d.com/Manual/class-LineRenderer.html
You can set a lot of options for how you want it to look and have multiple points for the line for a more complex path.
Thank you for your response, however how to function a checkbox or a event button to trigger the line to be created.
You want to subscribe the function that creates the line to the buttons on click event. https://docs.unity3d.com/2018.3/Documentation/ScriptReference/UI.Button-onClick.html For checkbox you need to use Toggles onValueChanged event https://docs.unity3d.com/2017.3/Documentation/ScriptReference/UI.Toggle-onValueChanged.html
How to use a button https://www.tutorialspoint.com/unity/unity_the_button.htm How to use a Toggle https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/script-Toggle.html
Wow! Thank you very much. All of these are really helpful. I really appreciate your help