Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Shadyfella13 · Feb 23, 2011 at 01:54 AM · guigui-window

GUI.Window IDs, will each individual unit need its own ID?

I am attempting to create a GUI for a strategy game. There are only a few unit types, but there are often more than one instance of a unit type on screen at the same time, and each instance will have its own set of buttons. I was hoping to create one GUI.Window, and change the information/functionality of the buttons in the window, depending on which unit is selected.

The problem I am having is if there is a clone of a unit in the game, only the original unit will display the GUI.Window on selection. So, I can switch between one soldier, and the Base building, but it will never pull up the GUI.Window for the second soldier.

Will I have to have a separate window ID for each individual unit? Is there another way to do this possibly? Thanks.

var iconA : Texture2D;

var iconB : Texture2D;

var unitName : String;

var buttonA : Rect = Rect (5, 20, 40, 40);

var buttonB : Rect = Rect (50, 20, 40, 40);

var buttonC : Rect = Rect (95, 20, 40, 40);

var buttonD : Rect = Rect (140, 20, 40, 40);

public var _showBaseActionBar = false;

public var _showSoldierActionBar = false;

var ActionBarWindowRect : Rect = Rect (0, Screen.height-60,185,65);

function Start () {

}

function OnGUI () {

var ActionBarWindowRect : Rect = Rect (0, Screen.height-60,185,65);

if (_showBaseActionBar == true) {

 unitName = "Base";

 ActionBarWindowRect = GUI.Window (0, ActionBarWindowRect, ActionBarBuilding, unitName);

}

if (_showSoldierActionBar == true) {

unitName = "Soldier";

ActionBarWindowRect = GUI.Window (1, ActionBarWindowRect, ActionBarSoldier, unitName);

}

}

function ActionBarBuilding (windowID : int) {

// Draw any Controls inside the window here

if (GUI.Button (buttonA, iconA)) {

 // execute button function here

}

if (GUI.Button (buttonB, iconA)) {

 // execute button function here

}

if (GUI.Button (buttonC, iconA)) {

 // execute button function here

}

if (GUI.Button (buttonD, iconA)) {

 // execute button function here

}

}

function ActionBarSoldier (windowID : int) {

// Draw any Controls inside the window here

if (GUI.Button (buttonA, iconB)) {

 // execute button function here

}

if (GUI.Button (buttonB, iconB)) {

 // execute button function here

}

if (GUI.Button (buttonC, iconB)) {

 // execute button function here

}

if (GUI.Button (buttonD, iconB)) {

 // execute button function here

}

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Shadyfella13 · Feb 24, 2011 at 08:20 PM

I worked out a solution, for anyone interested.

Instead of having one object in the scene that controls all the GUI elements, I put an OnGUI function in each units script. In my Unit manager, I build an array of all the objects tagged SOLDIER, and assign the index as the windowID. its still messy, but it works.

in the start function of the Soldier script...

    UnitID = UnitManager.GetInstance().CountSoldiers();
SOLDIER_WINDOW_ID = UnitID;

in the UnitManager script...

    public var soldiersInSceneList  = new Array();
function GetSelectedUnitsCount() {
return selectedUnitsList.length;

}

function CountSoldiers() {
return soldiersInSceneList.length + 1;

}

function AddSoldierCount(go : GameObject) {
soldiersInSceneList.Add(go);
}
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Apply Render Texture To GUI + Transparency? 2 Answers

Please! How can i close a GUI-Wndows or Button in Javascript? 1 Answer

GUILayout Window not working inside switch case for conditional menu 1 Answer

Creating a FlightSim Like GUI HUD for Showing the player the angle of the Camera. 1 Answer

talking with a npc 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges