2022-06-12 11:28:14 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class OpenPanelOnCollision : MonoBehaviour
|
|
|
|
{
|
|
|
|
|
|
|
|
public GameObject Panel;
|
|
|
|
public GameObject OtherPanel;
|
|
|
|
public GameObject SecondPanel;
|
|
|
|
public GameObject PanelAbove;
|
|
|
|
|
2022-06-12 17:18:43 +02:00
|
|
|
public GameObject obj;
|
|
|
|
|
|
|
|
private bool inRange = false;
|
|
|
|
|
2022-06-12 11:28:14 +02:00
|
|
|
private void OnTriggerEnter2D(Collider2D collision)
|
|
|
|
{
|
|
|
|
if(collision.tag == "Player")
|
|
|
|
{
|
2022-06-12 17:18:43 +02:00
|
|
|
inRange = true;
|
2022-06-12 11:28:14 +02:00
|
|
|
if(SecondPanel.active == false)
|
|
|
|
{
|
|
|
|
Panel.SetActive(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PanelAbove.SetActive(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-12 17:18:43 +02:00
|
|
|
private void OnTriggerStay2D(Collider2D collision)
|
|
|
|
{
|
|
|
|
if (collision.tag == "Player")
|
|
|
|
{
|
|
|
|
inRange = true;
|
|
|
|
if(OtherPanel.active == true)
|
|
|
|
{
|
|
|
|
if (SecondPanel.active == false)
|
|
|
|
{
|
|
|
|
Panel.SetActive(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SecondPanel.SetActive(false);
|
|
|
|
PanelAbove.SetActive(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (SecondPanel.active == false)
|
|
|
|
{
|
|
|
|
Panel.SetActive(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PanelAbove.SetActive(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IEnumerator Timer1()
|
|
|
|
{
|
|
|
|
yield return new WaitForSeconds(0.3f);
|
|
|
|
if(inRange == false)
|
|
|
|
{
|
|
|
|
Panel.SetActive(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IEnumerator Timer2()
|
|
|
|
{
|
|
|
|
yield return new WaitForSeconds(0.3f);
|
|
|
|
if (inRange == false)
|
|
|
|
{
|
|
|
|
PanelAbove.SetActive(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-12 11:28:14 +02:00
|
|
|
void Update()
|
|
|
|
{
|
2022-06-12 17:18:43 +02:00
|
|
|
|
|
|
|
if(obj.active == false)
|
|
|
|
{
|
|
|
|
if (Panel.active == true)
|
|
|
|
{
|
|
|
|
Panel.SetActive(false);
|
|
|
|
}
|
|
|
|
else if (PanelAbove.active == true)
|
|
|
|
{
|
|
|
|
PanelAbove.SetActive(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-12 11:28:14 +02:00
|
|
|
if(OtherPanel.active == true)
|
|
|
|
{
|
2022-06-12 17:18:43 +02:00
|
|
|
StartCoroutine(Timer1());
|
2022-06-12 11:28:14 +02:00
|
|
|
}
|
|
|
|
if(SecondPanel.active == false)
|
|
|
|
{
|
|
|
|
if(PanelAbove.active == true)
|
|
|
|
{
|
2022-06-12 17:18:43 +02:00
|
|
|
StartCoroutine(Timer2());
|
2022-06-12 11:28:14 +02:00
|
|
|
PanelAbove.SetActive(false);
|
|
|
|
Panel.SetActive(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnTriggerExit2D(Collider2D collision)
|
|
|
|
{
|
2022-06-12 17:18:43 +02:00
|
|
|
inRange = false;
|
2022-06-12 11:28:14 +02:00
|
|
|
if(Panel.active == true)
|
|
|
|
{
|
2022-06-12 17:18:43 +02:00
|
|
|
StartCoroutine(Timer1());
|
2022-06-12 11:28:14 +02:00
|
|
|
}
|
|
|
|
else if(PanelAbove.active == true)
|
|
|
|
{
|
2022-06-12 17:18:43 +02:00
|
|
|
StartCoroutine(Timer2());
|
2022-06-12 11:28:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|