πŸ“œ [Script] Tap / Touch Change Scene Object Script *Important

Options

Script:- Change Scene Objects on Tap

Ready to use Script

// Change Scene Objects on Tap Script 
// @input SceneObject[] items

// 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)

Steps to use:-

  • Create Scene Object
  • Add Script Component
  • Create Script In Resource Panel & Rename it as TouchScript
  • Add TouchScript to Scene Object Script
  • Copy Paste this Script & Save

Use:-

  • Change multiple objects on touch.
  • Create Empty Scene Object. Add Your Object 1 and Empty Object 2 to perform On / Off on Tap.
  • Change Multiple text on Touch.
  • Change Multiple Image Component on Touch.
  • Change Multiple 2d / 3d object on Touch.