Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class ButtonController : MonoBehaviour {
- public enum State {
- Idle, Win, Lose
- }
- public State state;
- public bool startButton;
- public GameObject Win, Lose;
- public List<ButtonController> list;
- private Button button;
- public Button GetButton() {
- return button;
- }
- void Start() {
- button = GetComponent<Button>();
- if (!startButton) {
- gameObject.SetActive(false);
- }
- button.onClick.AddListener(OnButtonClick);
- }
- void OnButtonClick() {
- button.interactable = false;
- for (int i = 0; i < list.Count; i++) {
- list[i].gameObject.SetActive(true);
- list[i].GetButton().interactable = true;
- }
- if (state == State.Win) {
- Debug.Log("Победа!");
- if (Win != null) {
- Win.SetActive(true);
- }
- } else if (state == State.Lose) {
- Debug.Log("Поражение!");
- if (Lose != null) {
- Lose.SetActive(true);
- }
- }
- }
- private void OnDrawGizmos() {
- Gizmos.color = Color.magenta;
- var pointA = transform.position;
- for (int i = 0; i < list.Count; i++) {
- if (list[i] != null) {
- var pointB = list[i].transform.position;
- Gizmos.DrawLine(pointA, pointB);
- }
- }
- if (startButton) {
- Gizmos.DrawWireSphere(transform.position, .5f);
- } else if (state == State.Win) {
- Gizmos.color = new Color(0f, 1f, 0f, 0.3f);
- Gizmos.DrawSphere(transform.position, .5f);
- } else if (state == State.Lose) {
- Gizmos.color = new Color(1f, 0f, 0f, 0.3f);
- Gizmos.DrawSphere(transform.position, .5f);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement