- Home /
How to make gameobjects hidden from start?
Hello, before explaining my problem, I'm new to Unity and beginner in programming. So my question may seem easy to solve. Anyway, I want to make 2 gameobjects (cube1 and cube2) and 1 toggle (Toggle3) to be hidden from start. And with additional toggles, I want to make them visible. For example, Toggle1 will make cube1 and Toggle3 visible while Toggle2 will make cube2 visible. Since I've tried to write down my code from different tutorials that I've found on net, it became very hard for me to detect the error. So how can I make these 2 objects hidden from start, and visible when I click on the toggles that I've mentioned?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class ViewModel : MonoBehaviour
{
public GameObject cube1;
public GameObject cube2;
public GameObject Toggle3;
void start(){
Toggle3.SetActive(false);
cube1.SetActive(false);
cube2.SetActive(false);
}
public void Toggle1_Changed(bool newValue)
{
cube1.SetActive(!cube1.activeInHierarchy);
Toggle3.SetActive(true);
}
public void Toggle2_Changed(bool newValue)
{
cube2.SetActive(!cube2.activeInHierarchy);
}
}
Your answer
Follow this Question
Related Questions
Why the text and the UI code is can't applying 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to position GUI Skin relative to screen size? 1 Answer
Find out if gameObject is UI in 4.6 1 Answer