2021年1月28日星期四

Increase score by one when clicking on an obj model

I tried a different approach to the game I wrote about in my previous question and I'm no longer getting the error message, but I'm still not sure how to increase the score.

I get this message every time I click on anything: you clicked this H {uuid: "BE82BBBC-D14B-4BD6-8582-B3080CB2C4D8", name: "", type: "Mesh", parent: qt, children: Array(0), …} and the message doesn't change whether I'm clicking on an obj model or not.

Here's the HTML code:

 <script src="https://aframe.io/releases/1.0.3/aframe.min.js"></script>      <script src="https://unpkg.com/aframe-environment-component@1.1.0/dist/aframe-environment-component.min.js                   "></script>      <script src = "https://code.jquery.com/jquery-3.4.1.min.js"></script>      <script src = "game.js"></script>    </head>    <body>      <a-scene start-game cursor="rayOrigin: mouse">        <a-entity environment ="preset: forest; fog: 0.9;"></a-entity>                    <a-obj-model class = "butterfly" src="PUSHILIN_butterfly.obj" mtl="PUSHILIN_butterfly.mtl" scale = "0.025 0.025 0.025" position = "0.2 2 -0.4" animation = "property: position; from: -0.4 1.60 -0.2; to: 0.5 1.59 -0.2; dur:1300; loop:true;" rotation="0 90 0"></a-obj-model>          <a-obj-model class = "bee" src="CHAHIN_BUMBLEBEE.obj" mtl="CHAHIN_BUMBLEBEE.mtl" scale = "0.07 0.07 0.07" position = "-0.1 1.75 -0.4" animation = "property: position; from: -0.4 1.64 -0.2; to: 0.5 1.67 -0.2; dur:3000; loop:true;"></a-obj-model>                <a-camera>                  <a-cursor shoot material="color: #FFE480;" geometry="primitive: ring"></a-cursor>        </a-camera>      </a-scene>    </body>  </html>  

Here's the Javascript code:

var scene;    function start() {    scene = $('a-scene')[0];    console.log("The scene is ready", scene);  }    AFRAME.registerComponent("start-game", {    init: start  });    AFRAME.registerComponent("shoot", {    schema: { type: "selector", points: {default: 1}},    init: function(){    $(this.el).on('click', function(event){      var aim = event.detail.intersection.point;      var clickedObj = event.detail.intersection.object;      console.log("you clicked this", clickedObj);    });   }  });    var score = 0;    function scorePlus() {    score++;    $('#score').text(score);    console.log(score);  }    $('.butterfly').click(scorePlus);    function scoreMinus() {    score--;    $('#score').text(score);  }    $('.bee').click(scoreMinus);    console.log(score);  document.getElementById("score");      function shoot(){    $(this.el).on('click', function(event){      var aim = event.detail.intersection.point;      var points = event.target.getAttribute('material').points;      console.log(points);    });  }   
https://stackoverflow.com/questions/65947441/increase-score-by-one-when-clicking-on-an-obj-model January 29, 2021 at 09:07AM

没有评论:

发表评论