https://github.com/normandy72/unity-cb-rb-tb
How to create a CheckBox, a RadioButton and a TextBox in Unity.
https://github.com/normandy72/unity-cb-rb-tb
csharp csharp-code unity unity2d unityui
Last synced: 11 days ago
JSON representation
How to create a CheckBox, a RadioButton and a TextBox in Unity.
- Host: GitHub
- URL: https://github.com/normandy72/unity-cb-rb-tb
- Owner: Normandy72
- Created: 2023-04-08T11:35:23.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-04-08T19:01:39.000Z (about 3 years ago)
- Last Synced: 2025-12-02T20:46:38.464Z (6 months ago)
- Topics: csharp, csharp-code, unity, unity2d, unityui
- Language: C#
- Homepage:
- Size: 1.44 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Instructions
## Checkbox
1. Create a __Canvas__, change its color if you need.
2. Add a __Toggle__ (UI -> Toggle). Change font size, checkmark size if needed.
3. In Toggle in _OnValueChanged_ component add new item, drop a Title, select GameObject -> SetActive.
## Radio Button
1. Create a __Canvas__, change its color if you need.
2. (not necessary) Add a __Panel__, change its size and color.
3. Add some __Text__ (may be Question).
4. Create __Empty GameObject__ (rename it to _Options_) for all answers.
5. Inside the Options create a __Toggle__ (UI -> Toggle), rename it, change Label Text, font size, position, etc.
6. Dublicate first option as many times as you need. Change info.
7. Add a __Toggle Group__ component to Options.
8. Select ALL toggles, in __Toggle__ component change _Group_ to "Options".
9. Inside the Panel create a __Button__ (rename to Submit Button).
10. Create a new __Script__. Add it to Options.
11. Create a Submit method. Inside a OnClick() component of SubmitButton add Options and check its Submit method.
12. You can also create a new __Sprite__ (2d objects -> sprites -> circle), and set it as a source image in toggle's background.
## Switch Toggle
1. Create a __Canvas__, change its color, size, etc.
2. Create an empty __GameObject__ (rename to _SwitchToggle_). Add an __Image__ inside (rename to _Background_), change its size and color.
3. In source image add a _bg1_ sprite.
4. Inside of Background add a new __Image__ (rename to _Handle_), in source image add a _handle1_ sprite.
5. Add text field if needed.
6. In SwitchToggle add a new component __Toggle__.
7. In Toggle component drop SwitchToggle background image into _Target Graphic_.
8. Create a new C# script (_SwitchToggle_). Add logic. Add this script to SwitchToggle.
9. For animation: download DoTween asset from Asset Store, import it. Add library in script. Add logic in script.
## Registration
#### Scene with TextBox, CheckBox and Button
1. Create a __Canvas__, change its color, size, etc.
2. Create text fields (in this case - for name, surname and age).
3. Add an __Imput Field__ for each text field (UI -> ImputField), change its size, color, placeholder, etc.
4. Add a __Toggle__, change its label, size, etc. In _Toggle_ component uncheck _IsOn_.
5. Add a __Button__, rename it to _SubmitButton_.
6. Add text fields for messages.
7. Create an empty __GameObject__ (rename to _CheckErrorController_).
8. Create a new script and attach it to CheckErrorController, add logic.
9. Create a text field for erroe message.