Three.js : How to return the script of a 3D Object?

270 Views Asked by At

I'm playing with three.js and especially the Editor where you can attach Script on 3D object. In Unity 3D you can access a script by using something like :

targetGameObject.GetComponent (scriptName).targetVariable;

How can you do this with three.js?

1

There are 1 best solutions below

1
msun On

If I understand correctly, "Scripts" aren't a fundamental component of ThreeJS -- not in the same way as they are in Unity3D. i.e., The "scripts" in ThreeJS Editor would be better off named "scripting code" or something like that. When you publish your app, these script functions get exported to JSON as strings and get evaluated upon their associated events -- but no tangible "Script" object/component actually results from them.

In other words, the "Scripts" you're referring to in Unity3D would be something you would have to build out yourself or use an existing library.