Question by
sarusian · Feb 20, 2017 at 03:29 AM ·
javascriptguireferencing
Closing GUI of another Script
I cant manage to close the GUI in Country.js from CanadaCore.js and since Country.js is a catch all GUI script for displaying country info and referencing CanadaCore.js would have to be repeated 130 times for each country so CanadaCore.js HAS to be the one to close the GUI
#pragma strict
//CanadaCore.js
//Technical Stuff
var obj : GameObject;
var isClicked : boolean = Country.isClicked;
// Population Stats
// Canada Population In Ones
static var CanadaPop : int = 36503478;
// Canada GDP In Millions
static var CanadaGDP = 1550536520000;
// Canada GDP Per Head
static var CanadaPPP;
// Population Dispalced In Canada
static var CanadianRefugees;
// Number Of Empty Canadian Rooms
static var CanadaHouses = 3578;
// Number Of Active Canadian Troops
static var CanadaTroops = 68250;
// Tonnes Of Stockpiled Food
static var CanadaFood = 12;
// Government Definitions: Democracy:0, Monarchy:1, Communist:2, Facist:3, Theocracy: 4
// FreeMovement dictates the probability of transmission of disease
// OpenBorders increases transmission risk from neighboring nations as well as increase incoming refugee numbers
// Politics
static var CanadaName : String = "Canada";
var Government = 0;
var OpenBorders = true;
var Funding = 0;
var Approval = 50;
var Generosity : float = .50;
// Geography
// Region 0 is North America
var Region = 0;
// 1% Chance of earthquake
var EarthquakeRisk = 1;
// 3% Chance of Pandemic
var PandemicChance = 3;
function Start () {
}
function Update () {
if (isClicked == false) {
Debug.Log("Closing DisplayCountryInfo");
}
}
function OnMouseDown() {
Debug.Log("Getting Data");
isClicked = true;
}
function OnGUI () {
if (isClicked == true) {
obj.GetComponent(Country).DisplayCountryInfo(CanadaPop,CanadaGDP,CanadaPPP,CanadianRefugees,CanadaHouses,CanadaTroops,CanadaFood,CanadaName,Government,OpenBorders,Region,EarthquakeRisk,PandemicChance,Funding,isClicked);
}
}
The next script cannot call to CanadaCore.js
#pragma strict
var Skin :GUISkin;
var exit : Texture;
var isClicked;
function Start () {
}
function Update () {
}
function DisplayCountryInfo(Population,GDP,PPP,Refugees,Houses,Troops,Food,Name,Government,Borders,Region,Earthquake,Pandemic,Funding,Closed) {
GUI.skin = Skin;
GUILayout.BeginArea(Rect (100,100,500,100));
GUILayout.Box("GPD Per Head: " + PPP + "$");
GUILayout.Box("Population: " + Population);
GUILayout.Box("GDP: " + GDP + " Trillion Dollars");
GUILayout.EndArea();
GUILayout.BeginArea(Rect(1300,40,20,20));
if(GUILayout.Button(exit)) {
Debug.Log("Closing DisplayCountryInfo");
isClicked = true;
}
GUILayout.EndArea();
Comment
You seem to be using the old UI system. It would be much easier to create a canvas. Add a panel for the information and set the panel to not be active.
For the information you could change a text UI on the panel to display the new information such as world GDP and what not....
It might be easier in the long run to use the new UI.
Your answer
![](https://koobas.hobune.stream/wayback/20220612111505im_/https://answers.unity.com/themes/thub/images/avi.jpg)