Advertisement
warlordkiyan

Untitled

Jul 27th, 2024
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. const Scene = require('Scene');
  2. const TouchGestures = require('TouchGestures');
  3. const Diagnostics = require('Diagnostics');
  4.  
  5. // Enables async/await in JS [part 1]
  6. (async function() {
  7.  
  8. let stick = null;
  9.  
  10. try {
  11. // Access the stick object from the scene
  12. stick = await Scene.root.findFirst('stick');
  13. if (stick) {
  14. Diagnostics.log('Stick object found');
  15. } else {
  16. Diagnostics.log('Stick object not found');
  17. return; // Exit if stick is not found
  18. }
  19.  
  20. // Check if transform is available
  21. if (!stick.transform) {
  22. Diagnostics.log('Stick transform is not available.');
  23. return;
  24. }
  25.  
  26. // Function to handle touch tap gesture
  27. function onTap(gesture) {
  28. if (!stick || !stick.transform) {
  29. Diagnostics.log('Stick object or transform is not available during tap gesture.');
  30. return;
  31. }
  32.  
  33. // Check if gesture location properties are defined
  34. if (gesture.location && gesture.location.x !== undefined && gesture.location.y !== undefined) {
  35. // Log tap gesture location for debugging
  36. Diagnostics.log('Tap gesture location: x=' + gesture.location.x.toString() + ', y=' + gesture.location.y.toString());
  37.  
  38. // Update stick position
  39. stick.transform.x = gesture.location.x;
  40. stick.transform.z = gesture.location.y; // Use y from gesture to move along z
  41.  
  42. } else {
  43. Diagnostics.log('Gesture location is not defined.');
  44. }
  45. }
  46.  
  47. // Subscribe to touch tap gestures
  48. TouchGestures.onTap().subscribe(onTap);
  49.  
  50. // Log messages for debugging
  51. Diagnostics.log('Touch gesture script is running.');
  52.  
  53. } catch (error) {
  54. Diagnostics.log('Error: ' + error.message);
  55. }
  56.  
  57. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement