I’m trying to make only one object from all lists randomly active
Help-me
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class CostumizeAction
{
public string CostumizeName;
public GameObject[] Costumizes;
}
public class CostumizeStart : MonoBehaviour {
public List<CostumizeAction> CostumizeParamers;
// Use this for initialization
void Start () {
int random = Random.Range (0, CostumizeParamers[AllIndex].Costumizes.Length);
CostumizeParamers[AllIndexs].Costumizes [random].SetActive (true);
}
// Update is called once per frame
void Update () {
}
}
for (int i = 0; i < CostumizeParamers.Count; i++)
{
int random = Random.Range(0, CostumizeParamers[i].Costumizes.Length);
CostumizeParamers[i].Costumizes[random].SetActive(true);
}
This is assuming that all other items are OFF. In the event that you ever need to change the … “Cosumizes”… at runtime you’ll need a better loop that toggles everything off except for the chosen index - which, hopefully after this you can see how that would work in a loop as you have control over the index and the chosen random value.