|
| 1 | +--- |
| 2 | +title: Scripting |
| 3 | +--- |
| 4 | + |
| 5 | +import { Callout } from 'fumadocs-ui/components/callout'; |
| 6 | + |
| 7 | +For reasons, custom code must either be generated by rebuilding the client (i.e., the Unity project) or via Cilbox (a sandbox CIL). |
| 8 | + |
| 9 | +## How to Add Scripts Via Unity Client Build |
| 10 | + |
| 11 | +- Create a canvas object with a button inside it. |
| 12 | + |
| 13 | +- Add a script to the button object. As a simple example, we'll create a script that updates a TMP text object called TestButton. |
| 14 | + |
| 15 | +- Create and assign a TMP text object to the Button Text field in the inspector. |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +``` cs title="TestButton.cs" |
| 20 | +public class TestButton : MonoBehaviour |
| 21 | +{ |
| 22 | + [SerializeField] private TextMeshPro buttonText; |
| 23 | + |
| 24 | + public void OnButtonClick() |
| 25 | + { |
| 26 | + buttonText.text = "Clicked!"; |
| 27 | + } |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | + |
| 32 | +- Select the button and add an onClick() event to it. Assign your Test Button Gameobject to it, making sure to select TestButton.OnButtonClick as the method which your button will call on when clicked. |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +- Add a Basis Prop component to the canvas Gameobject, enter an Asset Bundle Name and press the 'Create Prop Bee File' button. Use the Loadable Config Editor to generate an XML file. |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +- Open the BasisFramework prefab. In the Bundled Content Folder component's, add the generated .bee password and url. |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +- Run the Initialization scene. |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +- Build the Unity client. Your custom script will script will be included in the build. |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | +- Click the button and the TMP text object should update to show "Clicked!". |
| 55 | + |
| 56 | + |
0 commit comments