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
1
Question by Samir 1 · Jan 28, 2011 at 07:11 PM · hudweaponstower-defense

Tower Defence Weapon hud

First off i have a window which has 6 buttons, i want this to be my weapon cache. How do i go about setting each button to have a different weapon, and when clicked it will allow me in game to drag the current weapon onto a part of the map. Basically what i want is within many tower defence games where you select a weapon then place it on the map(minus the hud and buttons).

my code so far(only shows buttons and window which can be opened and closed):

using UnityEngine; using System.Collections;

public class MyGUI : MonoBehaviour { //public GUISkin mySkin;

public float buttonWidth = 5.0f; public float buttonHeight = 5.0f;

// / Weapon Cache window */

/*******/

private bool displayWeaponCache = true; private const int WEAPON_CACHE_ID = 1; private Rect weaponWindowRect = new Rect(525.0f, 5.0f, 50.0f, 400.0f); private int weaponCols = 1; private int weaponRows = 9;

// Use this for initialization void Start () {

}

// Update is called once per frame void Update () {

}

void OnGUI() { if (displayWeaponCache) { weaponWindowRect = GUI.Window(WEAPON_CACHE_ID, weaponWindowRect, WeaponCacheWindow, ""); }

if(GUI.Button(new Rect (575.0f, 5.0f, 25.0f, 25.0f),"X")) { displayWeaponCache= !displayWeaponCache; } }

public void WeaponCacheWindow(int winID) { for (int y = 0; y < weaponRows; y++) { for (int x = 0; x < weaponCols; x++) { GUI.Button(new Rect(5 + (x buttonWidth), 10 + (y buttonHeight),buttonWidth, buttonHeight), (x + y * weaponCols).ToString()); } } }

}

i also know this is a lot of work but im, only looking for tips and to be lead in the correct direction thanks much appreciated :D

Comment
Add comment · Show 1
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
avatar image Samir 1 · Jan 29, 2011 at 09:02 PM 0
Share

i've not got this question answered but i found an alternate way but it may not be best option. i set two buttons so far and when i click either button my boolean is set to true then i can click on map to instantiate the specified prefab. although whne i place it, it flips about a lot :s

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Samir 1 · Mar 06, 2011 at 04:36 PM

I have found a way to do this now so thanks anyway :)

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
avatar image
0

Answer by slkjdfv · Mar 06, 2011 at 04:52 PM

where you do this

public void WeaponCacheWindow(int winID)
{
    for (int y = 0; y < weaponRows; y++)
    {
        for (int x = 0; x < weaponCols; x++)
        {
            GUI.Button(new Rect(5 + (x * buttonWidth), 
            10 + (y * buttonHeight),buttonWidth, buttonHeight), 
            (x + y * weaponCols).ToString());
        }
    }
}
try this instead

public void WeaponCacheWindow(int winID)
{
    for (int y = 0; y < weaponRows; y++)
    {
        for (int x = 0; x < weaponCols; x++)
        {
            float myTempString = (x + y * weaponCols);
            if (GUI.Button(new Rect(5 + (x * buttonWidth), 
            10 + (y * buttonHeight),buttonWidth, buttonHeight), 
            (x + y * weaponCols).ToString()))
            {
                if(myTempString == 0)
                {
                //This is where you put the code to instantiate the object selected
                }
            }
        }
    }
}
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

Bootcamp Weapon Hud & Reloading Problem 2 Answers

Dynamically pass integer values into separate scripts in C#? 4 Answers

HUD with health and stamina 1 Answer

Is there anyway to fade in/out a GUI image without using an addon/asset? 2 Answers

Make a RPM Display For my Car 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