[ENGINE ONLY] Mouse Lock Script

To what enity I have to attach this script: ?
https://playcanvas.com/editor/code/438440?tabs=5682608

There must be something like, or?

???.addComponent(‘script’);
???.script.create(‘mouseLock’);

Hi @iso74,

That script doesn’t reference any entity component, so it can function on any regular entity.

myEntity.addComponent('script');
myEntity.script.create('mouseLock');

@Leonidas Thanks, silly me, you’re right of course.
I did attach it to the camera, which makes sense and it works :slight_smile:

1 Like

@Leonidas Btw. if I want to attach multiple scripts to the camera, do I have every time to add another component?

camera.addComponent(‘script’);
camera.script.create(‘secondScript’);
camera.addComponent(‘script’);
camera.script.create(‘thirdScript’);

etc…

No, all pc scripts are created on the single script component.

You can only have one instance of each component type on each Entity.

2 Likes