/
/
/ "BRO TIGER"2017-08-21 07:42:24
C++ / C#
/ "BRO TIGER", 2017-08-21 07:42:24

Problem with Popup Window in Game (A Certain DebugHUB)?

Good day! Most of the Build System is already done and I wondered: How to make a pop-up window that would tell the user why the part is not placed? Made the restrictions everything works, but a few messages do not pop up! Tell me, maybe I'm wrong about something? Thanks in advance!
Here is the Build Manager script (Parts related to the "Debug" Manager)

using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;

public class BuildingHUB : MonoBehaviour {

    public GameObject debugHUB;

    public Text debugText;
    public Text countText;
    public Text massText;
    public Text energyText;
    public Text strenghText;

    //Для работы из вне в скрипте Строительства!
    public int maxCount = 40;
    public int count;

    public void DebugHUB()
    {
        PlayerShip PS = playerShip.GetComponent<PlayerShip>();

        int energy = PS.energy;
        int maxEnergy = PS.maxEnergy;
        energyText.text = energy.ToString() + " / " + maxEnergy.ToString();

        count = details.Length;
        countText.text = count.ToString() + " / " + maxCount.ToString() + " ШТ.";


        //Debug с количеством деталей - Работает!
        if (count == maxCount)
        {
            debugHUB.SetActive(true);
            debugText.text = "ВНИМАНИЕ! КОЛИЧЕСТВО ДЕТАЛЕЙ ОГРАНИЧЕНО, УДАЛИТЕ НЕНУЖНЫЕ ДЕТАЛИ ЧТОБЫ ПОСТАВИТЬ ДРУГИЕ!";
        }
        else
        {
            debugHUB.SetActive(false);
            debugText.text = "";
        }

        if (PS.energy + detailRefs.energy < PS.maxEnergy)
        {
            debugHUB.SetActive(true);
            debugText.text = "ВНИМАНИЕ! НЕДОСТАТОЧНО ЭНЕРГИИ! УВЕЛИЧЬТЕ МАКСИМАЛЬНЫЙ ПОКАЗАТЕЛЬ С ПОМОЩЬЮ ГЕНЕРАТОРОВ!";
        }
        else
        {
            debugHUB.SetActive(false);
            debugText.text = "";
        }
    }
}

Just in case, the Build script (Part of it)
public void Build()
    {
        PlayerShip PShip = ship.transform.GetComponentInParent<PlayerShip>();
        PreviewObject PS = currentpreview.GetComponent<PreviewObject>();
        DetailRefs DR = currentobject.prefab.GetComponent<DetailRefs>();

        float mass = 0;

        if (PS.IsBuildable)
        {
            if (PShip.energy + DR.energy < PShip.maxEnergy)
            {
                if (buildingHUB.count < buildingHUB.maxCount)
                {
                    GameObject GO = (GameObject)Instantiate(currentobject.prefab, currentpos, Quaternion.Euler(currentrot));
                    GO.transform.SetParent(ship.transform);

                    PShip.strength += DR.strength;
                    PShip.energy += DR.energy;

                    Collider[] cols = GO.transform.GetComponentsInChildren<Collider>();
                    //Debug.Log("Количество коллайдеров в новом объекте: " + cols.Length);

                    foreach (Collider col in cols)
                    {
                        float volume = col.bounds.size.x * col.bounds.size.y * col.bounds.size.z;
                        mass += volume;
                    }
                }
            }
        }
        //Debug.Log("Прибавление массы: " + mass);
        ship.transform.GetComponentInParent<Rigidbody>().mass += mass;
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Griboks, 2017-08-21
@BRO_TIGER

Both posts seem to be correct. However, the messages are displayed at the same time! Therefore, one message may well overlap another.
I recommend making some kind of debug manager with a message queue. So that when you press ok, the following is displayed.
DebugHub.AddToQuee(count==maxcount,"WARNING! QUANTITY");
Another option - the conditions are written incorrectly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question