-
Notifications
You must be signed in to change notification settings - Fork 47
/
component5.js
27 lines (25 loc) · 871 Bytes
/
component5.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
AFRAME.registerComponent('hello', {
schema: {
message: {type: 'string', default: 'Hello!'},
event: {type: 'string', default: ''},
},
init: function () {
var data = this.data; // Component property values.
var el = this.el; // Reference to the component's entity.
var pos_y = 1;
if (data.event) {
// This will log the `message` when the entity emits the `event`.
el.addEventListener(data.event, function () {
console.log(data.message);
var box = document.createElement("a-box");
box.setAttribute('color', 'red');
box.setAttribute('position', {x: 0, y: pos_y, z: 0});
el.appendChild(box);
pos_y += 1;
});
} else {
// `event` not specified, just log the message.
console.log(data.message);
};
}
});