mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/MI-38.git
synced 2026-01-24 06:55:38 +03:00
04.07.2022
This commit is contained in:
106
Heli_with_panels/Assets/Scripts/Panel2D/ToggleScript.cs
Normal file
106
Heli_with_panels/Assets/Scripts/Panel2D/ToggleScript.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ToggleScript : MonoBehaviour
|
||||
{
|
||||
public GameObject[] tog;
|
||||
int mouseY_;
|
||||
int curMouseY_;
|
||||
bool defTog;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
OnTog0();
|
||||
|
||||
}
|
||||
public void OnClick()
|
||||
{
|
||||
if (tog.Length < 3)
|
||||
{
|
||||
OnTog2();
|
||||
}
|
||||
else
|
||||
{
|
||||
OnTog0();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
void OnTog0()
|
||||
{
|
||||
tog[0].SetActive(true);
|
||||
defTog = true;
|
||||
for (int i = 1; i < tog.Length; i++)
|
||||
{
|
||||
tog[i].SetActive(false);
|
||||
}
|
||||
}
|
||||
void OnTog2()
|
||||
{
|
||||
for (int i = 0; i < tog.Length; i++)
|
||||
{
|
||||
if (tog[i].activeSelf == true)
|
||||
{
|
||||
tog[i].SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
tog[i].SetActive(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public void OnMouseDown()
|
||||
{
|
||||
mouseY_ = (int)Input.mousePosition.y;
|
||||
//Debug.Log($"mouseY {mouseY_}");
|
||||
}
|
||||
public void OnMouseUp()
|
||||
{
|
||||
curMouseY_ = (int)Input.mousePosition.y;
|
||||
if (curMouseY_ != mouseY_)
|
||||
{
|
||||
//Debug.Log($"curMouseY {curMouseY_}");
|
||||
int dMY = mouseY_ - curMouseY_;
|
||||
if (tog.Length < 3)
|
||||
{
|
||||
OnTog2();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(defTog == true)
|
||||
{
|
||||
defTog = false;
|
||||
if (dMY < 0)
|
||||
{
|
||||
tog[0].SetActive(false);
|
||||
tog[1].SetActive(true);
|
||||
tog[2].SetActive(false);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
tog[0].SetActive(false);
|
||||
tog[1].SetActive(false);
|
||||
tog[2].SetActive(true);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
OnTog0();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user