javascript - Random Aframe environment -


i want have random scenarios every time enter website. i'm trying return pickscenario variable js script aframe in line <a-entity environment="preset: pickscenario"></a-entity>

here's code:

<a-entity environment="preset: pickscenario"></a-entity>         <script>              var scenarios = ['ocean', 'universe', 'forest'];              var pickscenario = scenarios[math.floor(math.random()*scenarios.length)];              return pickscenario;         </script> 

i bet quite simple haven't figure out yet.

for scripts take effect advised write components, this:

<script type="text/javascript"> aframe.registercomponent('randomscenario', {    init: function(){        var scenarios = ['ocean', 'universe', 'forest'];        var pickscenario = scenarios[math.floor(math.random()*scenarios.length)];        this.el.setattribute('environment', { preset: pickscenario});    } }); </script> 

and in html:

<a-entity randomscenario></a-entity> 

the init function called when scene loaded.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -