Hello! I am still learning and I dont understand why I cannot get an attribute values from another script. My setup is two scripts - One with the name PickerRaycast (which is attached to a camera) and one with the name Pos1Attributes which is attached to an box entity.
The basic idea is that I want to get the attribute values of the individual entities with a mouse click. When I try the code I get the error: Uncaught TypeError: Cannot read property ‘get’ of undefined
What am I doing wrong?
Thanks in advance!
var Pos1Attributes = pc.createScript('Pos1Attributes');
Pos1Attributes.attributes.add('x', {
type: 'number'
});
Pos1Attributes.attributes.add('y', {
type: 'number'
});
Pos1Attributes.attributes.add('z', {
type: 'number'
});
Pos1Attributes.attributes.add('rotation', {
type: 'number'
});
----------------------------------------------------------------------------
var PickerRaycast = pc.createScript('pickerRaycast');
// initialize code called once per entity
PickerRaycast.prototype.initialize = function() {
this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.onSelect, this);
};
PickerRaycast.prototype.onSelect = function (e) {
var from = this.entity.camera.screenToWorld(e.x, e.y, this.entity.camera.nearClip);
var to = this.entity.camera.screenToWorld(e.x, e.y, this.entity.camera.farClip);
this.app.systems.rigidbody.raycastFirst(from, to, function (result) {
var pickedEntity = result.entity;
var data = {
command: "Teleport",
x: pickedEntity.attributes.get('x'),
y: pickedEntity.attributes.get('y'),
z: pickedEntity.attributes.get('z'),
rotation: pickedEntity.attributes.get('rotation'),
};
});
};