how to make gameobject randomly visible ? i really need this please
I didn't find anything that really answered this question i want to make those "quiz menus" (1 to 9 ) randomly SetActive(true) i tried this code but didnt work
public class Controller3 : MonoBehaviour
{
public GameObject[] spawnPoints;
public GameObject currentPoint;
int index;
void Start()
{
spawnPoints = GameObject.FindGameObjectsWithTag("quiz");
index = Random.Range(0, spawnPoints.Length);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("point"))
{
currentPoint = spawnPoints[index];
currentPoint.SetActive(true);
}
}
}
sans-titre.png
(6.0 kB)
Comment
Answer by Oribow · Apr 24, 2016 at 08:42 PM
Ok, made you something. When you click your left mouse button, a new question will be visible. Beware, that each question can be choosen multiple times.
GameObject[] questions;
GameObject currentActiveQuestion;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
if (currentActiveQuestion != null)
currentActiveQuestion.SetActive(false);
currentActiveQuestion = questions[Random.Range(0, questions.Length)];
currentActiveQuestion.SetActive(true);
}
}