Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
147 views
in Technique[技术] by (71.8m points)

javascript - Cannot read property 'xy' of undefined

I'm trying to increase the score by one when I click on an a-obj model, but I keep getting an error message that says:

Uncaught TypeError: Cannot read property 'getAttribute' of undefined
at HTMLElement.<anonymous> (game.js:17)
at HTMLElement.dispatch (jquery-3.4.1.min.js:2)
at HTMLElement.v.handle (jquery-3.4.1.min.js:2)
at HTMLElement.emit (aframe.min.js:897)
at i.twoWayEmit (aframe.min.js:796)
at i.onCursorUp (aframe.min.js:796)
at HTMLCanvasElement.<anonymous> (aframe.min.js:1038)

Most of the code is copied from another project I did where it worked, but for some reason it isn't working with the 3d models.

Here is the HTML code:

 <script src="https://aframe.io/releases/1.0.3/aframe.min.js"></script>
    <script src="https://unpkg.com/[email protected]/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 = "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-entity shoot="points: 1"><a-obj-model src="PUSHILIN_butterfly.obj" mtl="PUSHILIN_butterfly.mtl" scale = "0.025 0.025 0.025" position = "-0.4 1.70 -0.2"></a-obj-model></a-entity>
   <a-camera>
                <a-cursor shoot material="color: #FFE480;" geometry="primitive: ring"></a-cursor>
      </a-camera>
    </a-scene>
  </body>
</html>

Here is the Javascript code:

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 = this.el.getAttribute('material').points;
    console.log(points);
  });
}
question from:https://stackoverflow.com/questions/65892733/cannot-read-property-xy-of-undefined

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...