I want to add an existing script to an entity by code just like what I did in editor,is there any proper way to do this?
Hi @FBplus,
Sure, to do that you need to add a script component first, if the entity doesn’t have one yet:
entity.addComponent("script");
And then you add scripts using their script type name (usually found in the first line of each script where it’s defined):
entity.script.create('playerController', {
attributes: {
speed: 4
}
});
If you would like, you can optionally pass script attribute values as well.
1 Like
Thanks so much Leonidas:
1 Like