Scripting Examples
A collection of useful script snippets and examples.
Last updated
A collection of useful script snippets and examples.
Last updated
If you are new to scripting we highly recommend reading the following guides first:
Below you will find a few basic scripts as a quick reference.
We also offer a lot of sample scenes and complete projects that you can download and use as a starting point:
@
see for all component events
@
Add this script to any object in your scene that you want to be clickable. Make sure to also have an ObjectRaycaster
component in the parent hierarchy of that object.
test
Add this script to any object in your scene that you want to be clickable. Make sure to also have an ObjectRaycaster
component in the parent hierarchy of that object.
The component will send the received click to all connected clients and will raise an event that you can then react to in your app. If you are using Unity or Blender you can simply assign functions to call to the onClick
event to e.g. play an animation or hide objects.
You can nest objects and their data. With properly matching @serializable(SomeType)
decorators, the data will be serialized and deserialized into the correct types automatically.
::: tip Without the correct type decorators, you will still get the data, but just as a plain object. This is useful when you're porting components, as you'll have access to all data and can add types as required. :::
To use the effect add it to the same object as your Volume
component.
This is an example how you could create your own audio component. For most usecases however you can use the core AudioSource component and don't have to write code.
页面由 AI 自动翻译
@
::: tip Find a to download and try :::
@
@
@
@
This can be useful if you want to run your custom animation logic. You can also export an array of clips. @
@
::: tip
EventList events are also invoked on the component level. This means you can also subscribe to the event declared above using myComponent.addEventListener("my-event", evt => {...})
as well.
This is an experimental feature. Please provide feedback in our
:::
This is useful for when you want to expose an event to Unity or Blender with some custom arguments (like a string) @
Example use:
In your typescript component: @
In C# in any script: @
::: tip Keep in mind that you still have access to all web apis and packages! That's the beauty of Needle Engine if we're allowed to say this here 😊 :::
@
@
Assuming you have a custom shader with a property name _Speed
that is a float value this is how you would change it from a script.
You can find a live
See on StackBlitz
Make sure to install in your web project. Then you can add new effects by deriving from PostProcessingEffect
.
Here is an example that wraps the . You can expose variables and settings as usual as any effect is also just a component in your three.js scene.
@
@
@
Use the FileReference type to load external files (e.g. a json file) @