Question by
Theoduras · Apr 15, 2019 at 03:13 PM ·
scripting problem
onMouseDown active self on siblings
I am creating a map where you're able to click a gameObject. On click it shows an information screen. When clicked again it toggles the screen off.
The map has multiple markers and information screens. If you click one marker and you have another screen opened, it has to close the open screen and open the other screen.
The following code does just that, but I want it to close all markers without adding new gameObjects as public items. This example is okay with 2-3 markers, but gets really bad to control with a lot of markers.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class showScreen : MonoBehaviour
{
public GameObject infoScreen;
public GameObject buildingBlock;
public GameObject infoScreen2;
// Use this for initialization
void Start()
{
infoScreen.SetActive(false);
}
// Update is called once per frame
void Update()
{
}
void OnMouseDown()
{
if (infoScreen.activeSelf == false)
{
infoScreen.SetActive(true);
}
else
{
infoScreen.SetActive(false);
}
if (infoScreen2.activeSelf == true){
infoScreen2.SetActive(false);
}
}
}
Comment