How to approach, from the second script, to a variable lights [currentIndex] which is the array? Sorry for the bad English Thank you for advice
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LightSwitchObj : MonoBehaviour {
public GameObject[] lights;
public static int currentIndex = 0;
float elapsedTime = 0f; // Counts up to repeatTime
float repeatTime = 2f; // Time taken to repeat in seconds
void Update(){
elapsedTime += Time.deltaTime;
if (elapsedTime >= repeatTime)
{
NewRandomObject();
elapsedTime -= repeatTime;
}
}
public void NewRandomObject()
{
int newIndex = Random.Range(0, lights.Length);
// Deactivate old gameobject
lights[currentIndex].SetActive(false);
// Activate new gameobject
currentIndex = newIndex;
lights[currentIndex].SetActive(true);
}}