I’m still getting my bearings after moving from Unity. One issue I’m having that will probably be an easy fix(!) is accessing functions from other objects. I want a game manage which will have references to other management classes. Firstly, whats the best way to reference this? I currently create an empty object and attach the script to that, then I can add the other objects to the manager script. Secondly is this the best way to reference them:
I’ve looked through the docs and it says this is the best way to reference an entity. In the GameManager class I’m trying to access a function from uiManager but I cannot find the correct way to do this.
I’ve seen techniques like // this.uiManager.script.changeQuestions("some text") but I get errors such as uiManager not defined, even though the reference is there in the editor.
BTW this is the function I’m trying to call in the referenced class.
I’m trying to get my code organised with relevant managers for each functions but this seems pretty difficult at the moment and I don’t really want to start making god classes.
So to access a function in a script attached to an entity you have to do entity.script.[scriptname].function(), it looks like you’re missing the script name in your function call.
The game manager is attached to the camera with the entities added in the inspector. The code I’m trying to run is in the game manager class if anyone can help.
var SomeScript = pc.createScript('SomeScript');
SomeScript.attributes.add('_model', {
type:'entity',
});
var att = self._model;
// initialize code called once per entity
SomeScript.prototype.initialize = function() {
var model=this.SomeScript;
console.log(model);
console.log(att);
console.log(att.script);
console.log(model.script);
};
// update code called every frame
SomeScript.prototype.update = function(dt) {
};
the goal is to reach to the scripts attribute of the model so I can eventually activate a function on another script.
as you can see the attempt is both on the same model and the variable model.
in both cases console.log(model); and console.log(att); the result was undefined.
in both cases console.log(att.script); and console.log(model.script);I receive the errorCannot read property ‘script’ of undefined`
could you help me figure what did i do wrong?