Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Scene = require('Scene');
- const TouchGestures = require('TouchGestures');
- const Diagnostics = require('Diagnostics');
- // Enables async/await in JS [part 1]
- (async function() {
- let stick = null;
- try {
- // Access the stick object from the scene
- stick = await Scene.root.findFirst('stick');
- if (stick) {
- Diagnostics.log('Stick object found');
- } else {
- Diagnostics.log('Stick object not found');
- return; // Exit if stick is not found
- }
- // Check if transform is available
- if (!stick.transform) {
- Diagnostics.log('Stick transform is not available.');
- return;
- }
- // Function to handle touch tap gesture
- function onTap(gesture) {
- if (!stick || !stick.transform) {
- Diagnostics.log('Stick object or transform is not available during tap gesture.');
- return;
- }
- // Check if gesture location properties are defined
- if (gesture.location && gesture.location.x !== undefined && gesture.location.y !== undefined) {
- // Log tap gesture location for debugging
- Diagnostics.log('Tap gesture location: x=' + gesture.location.x.toString() + ', y=' + gesture.location.y.toString());
- // Update stick position
- stick.transform.x = gesture.location.x;
- stick.transform.z = gesture.location.y; // Use y from gesture to move along z
- } else {
- Diagnostics.log('Gesture location is not defined.');
- }
- }
- // Subscribe to touch tap gestures
- TouchGestures.onTap().subscribe(onTap);
- // Log messages for debugging
- Diagnostics.log('Touch gesture script is running.');
- } catch (error) {
- Diagnostics.log('Error: ' + error.message);
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement