Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How do I to turn off items on a button click

Discussion in 'AR/VR (XR) Discussion' started by JBEDUnity, Jul 21, 2020.

  1. JBEDUnity


    Jul 13, 2020
    Not sure what's going on here but I just want to be able to switch between things being on or off as I click on a button.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class InputTest : MonoBehaviour
    // Start is called before the first frame update
    void Start()


    // Update is called once per frame
    void Update()
    public GameObject[] objects;
    public int activeIndex = 0;
    public int aIndex;

    if (OVRInput.Get(OVRInput.Button.One))
    activeIndex = aIndex;
    for (int i = 0; i < objects.Length; i++)
    objects.SetActive(i == activeIndex);