Obj Touch Controller

Hi there!
I’ve tried to achieve a circling of 3 different objects on tap on another controlling object (like button)
So, I have a script that change visibility of objects by tap on the screen, but how to assign by obj tap?

// @input SceneObject[] items
// @input Component.BaseMeshVisual TouchTarget 

// Arrays are indexed from 0.
// Disable everything but the first (0th) item .
for (var i = 1; i < script.items.length; i++) {
 script.items[i].enabled = false;
}

// We remember what item is currently visible.
// When we start it's the 0th item.
var currentItemIndex = 0;

// Define what happens when you tap.
function activateNextItem () {
 // Disable the current item. 
 script.items[currentItemIndex].enabled = false;

 // Increment the current item index
 currentItemIndex += 1;

 // We need the current item index to wrap around 
 // once it's higher than the number of items we have.
 currentItemIndex = currentItemIndex % script.items.length;

 // Enable the new item. 
 script.items[currentItemIndex].enabled = true;
}

// Bind the function to the touch event.
var touchEvent = script.createEvent("TapEvent");
touchEvent.bind(activateNextItem)

I have been struggling with the touch gestures and interactions in LS. Seems like a lot of functionality is missing. You might need to do a raycast/hittest from the camera to the object to determine if it was tapped.

:anguished:
but if this object rendering on screen, I mean its just a screen image

I found this function in the Behavior script
but can get how to connect this two

function setupTouchEvent() {
    var targetScript = script;
    if (script.touchEventTouchTarget) {
        var targetObj = script.touchEventTouchTarget.getSceneObject();
        var touchComponent = getOrAddComponent(targetObj, "Component.TouchComponent");
        touchComponent.addMeshVisual(script.touchEventTouchTarget);
        targetScript = targetObj.createComponent("Component.ScriptComponent");
    }
    targetScript.createEvent(script.touchEventEventType).bind(onTrigger);
}

TouchComponent doesn’t exist any more as far as I can tell. Anyway, that script is basically just dynamically creating a script component and then adding an event to it. If your script is on the object you want to add the event to, it’s the same as doing something like this:

script.createEvent("TapEvent").bind(onTrigger);

Anyway, take a look at the UI interface helper in the library. It has some extremely convoluted scripts to help determine which button is being pressed.

This determines which button is being pressed and forwards the touch events.

function claimTouchStart(touchPosition) {
    return (thisScreenTransform && thisScreenTransform.containsScreenPoint(touchPosition))
        ? global.TouchClaimTypes.Claim
        : global.TouchClaimTypes.Reject;
1 Like

ohhh, I already have UI which switch mode of some assets, and now I need to add switching for another asset by a tap on the screen, so, I create some occluder image which placed above UI and that prevents tap function when its UI tapping. Thank you, need to dive in.

Yes! I solve it!
It much easier then we thought :smiley:
Just add interaction to your button object and add ‘change on tap’ script and its work :wink:
Снимок экрана 2021-09-30 в 11.52.13|326x500

The touch component was renamed to interaction or something - whatever Jorik ended up adding.

1 Like