CREATE YOUR WORLD
Scripting
$ref & $unref
5min
The ref and out keywords in C# are used when passing references to variables or structures to methods.
In TypeScript, these keywords are not available, but in ZEPETOScript, you can achieve similar functionality using $ref and $unref.
Functions | Description |
---|---|
$ref(x?:T):$Ref | Creates a reference for a parameter |
$unref(x:$Ref):T | Releases the reference of a parameter and returns the original value |
For the example, let's set up a Scene as follows:
- Add a 3D object, Cube, to the Scene.
- In the Inspector for the added Cube, click "Add Component" and add a Rigidbody.
- Add an Empty GameObject to the Scene.
- Write the RefSample script below and add it to the GameObject created in step 3.
- Create another ZEPETOScript and write the TestScript below.
- Drag and connect TestScript to the Cube's Inspector.
- Click the [▶︎(play)] button to observe the results.
- You can check the success of referencing objects, Rigidbody components, and ZEPETOScript components in the console log window.