Question by
flashpaypay · Feb 10, 2021 at 09:34 PM ·
buttongamefreezeclick
Game window gets freeze when i click on a button
Hi! Im testing two clickable buttons to make appear and disappear some trees in my game. The dissapear button works fine, but when i click in the other button, my game get freeze. Left button -> Make some trees appear.
Right button-> make them dissapear My trees are in a parent called Arboles autoctonos.
Code for ON button:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BotonON : MonoBehaviour
{
public GameObject Arboles;
public bool arbolesVisibles;
void Update()
{
}
void OnMouseDown()
{
arbolesVisibles = true;
for (int i = 0; i < 5; i++)
{
Arboles.transform.GetChild(i).gameObject.SetActive(true);
}
}
}
Code for OFF button:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BotonOFF : MonoBehaviour
{
public GameObject Arboles;
public bool arbolesVisibles;
void Update()
{
}
void OnMouseDown()
{ //THIS FUNCTION WILL DETECT THE MOUSE CLICK ON A COLLIDER,IN OUR CASE WILL DETECT THE CLICK ON THE BUTTON
arbolesVisibles = false;
for (int i = 0; i < 5; i++)
{
Arboles.transform.GetChild(i).gameObject.SetActive(false);
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613024949im_/https://answers.unity.com/themes/thub/images/avi.jpg)