Hi ı have a 2 buttons one in behind is shows when cursor is not on it.Other shows when cursor on it.And when
cursor exit second button disappear but if you move cursor fast it does not disappear
GameObject[] buttons;
GameObject cam;
getscene getsaveload;
bool is_cursor_on=false;
private void Awake()
{
cam = GameObject.FindGameObjectWithTag("MainCamera");
getsaveload = cam.GetComponent<getscene>();
buttons = new GameObject[8];
for (int a = 1; a < 9; a++)
{
buttons[a-1] = GameObject.Find("button_" + a.ToString());
}
}
void Start()
{
for (int a = 1; a < buttons.Length; a += 2)
{
buttons[a].SetActive(false);
}
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
button_clicked();
}
}
private void OnMouseEnter()
{
hide_button();
}
private void OnMouseExit()
{
show_button();
}
void hide_button()
{
switch(gameObject.name)
{
case "button_1":
buttons[1].SetActive(true);
break;
case "button_3":
buttons[3].SetActive(true);
break;
case "button_5":
buttons[5].SetActive(true);
break;
case "button_7":
buttons[7].SetActive(true);
break;
}
}
void show_button()
{
switch (gameObject.name)
{
case "button_2":
buttons[1].SetActive(false);
break;
case "button_4":
buttons[3].SetActive(false);
break;
case "button_6":
buttons[5].SetActive(false);
break;
case "button_8":
buttons[7].SetActive(false);
break;
}
}
void button_clicked()
{
switch (gameObject.name)
{
case "button_2":
getsaveload.savefiles();
break;
case "button_4":
getsaveload.loadfiles();
break;
case "button_6":
SceneManager.LoadScene("trying_s_1");
break;
case "button_8":
Application.Quit();
break;
}
}