0

I am passing a camera name (cam: string) to a method called switchCameraTo(cam){} and at one point, I would like to write something like:

switchCameraTo(cam){
  this.UniCamera.attachControl(this.canvas, true);
  this.scene.activeCamera = this.UniCamera;
}

This works, but if I replace "this.UniCamera" by "cam" to pass the argument, it fails. "this.cam" won't work either. Note that "this.UniCamera" was declared in the constructor of the class where the method is located.

The argument "cam", contains the string "UniCamera".

Is there an solution to this problem? I think it might be a type error but I'm not sure how to fix this. Any help will be welcome!

Thank you!

Student
  • 135
  • 2
  • 13
  • 1
    See the [linked question](https://stackoverflow.com/questions/4244896/dynamically-access-object-property-using-variable)'s answers. Basically, `this.scene.activeCamera = this[cam];` – T.J. Crowder Feb 01 '20 at 16:48
  • 1
    Wow! Thank you! That's an interesting page: I didn't know how to phrase my question better/differently so I did not find that thread. Thanks again! – Student Feb 01 '20 at 20:37

0 Answers0