Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Custardcs · Sep 01, 2015 at 05:12 PM · unity 5spawninghud

Using Buttons to create units only when selecting the barracks.

Hi i need a little help here...

basically i need to click on a object like the (barracks)

then have it change the buttons on the hud to what ever i place them inside to be..

for example button 1 will spawn a sniper button 2 will spawn a rocketguy etc

at the moment i have my barracks spawning the two units by pressing keys on the keyboard..

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class Buildings : MonoBehaviour
 {
     //Buttons for Hud
 
     public Rigidbody BuildQPrefab1, BuildQPrefab2;
     public Transform spawn;
 
     //drag Selection
     public bool selected = false;
     //private Vector3 moveToDest = Vector3.zero;
     public float floorOffSet = 1;
     //Click Select
     private bool selectionByClick = false;
     
     
     // Update is called once per frame
     private void Update () 
     {        
         HudButtonsUsage ();
 
         //Place Layer Unit Control Here.
         if (Input.GetMouseButton (0)) 
         {
             if (!selectionByClick)
             {
                 Vector3 camPos = Camera.main.WorldToScreenPoint (transform.position);
                 camPos.y = CamOP.InvertMouseY(camPos.y);
                 selected = CamOP.selection.Contains (camPos);
             }
             if (selected)
                 gameObject.GetComponentInChildren<Projector>().enabled = true;
             else
                 gameObject.GetComponentInChildren<Projector>().enabled = false;
         }
 
     
     }
     //Function for Spawning
     private void HudButtonsUsage()
     {
         //This Must be the first Button on the HUD
         if (Input.GetKeyUp ("t"))
         {
             Instantiate(BuildQPrefab1, spawn.position, spawn.rotation);
         }
         //This Must be the Second Button on the HUD
         if (Input.GetKeyUp ("y"))
         {
             Instantiate(BuildQPrefab2, spawn.position, spawn.rotation);
         }
     }
 
     //Function for SimpleMouseClick
     private void OnMouseDown()
     {
         selectionByClick = true;
         selected = true;
     }
     private void OnMouseUp()
     {
         if (selectionByClick)
             selected = true;
         
         selectionByClick = false;
     }
 }
 

This is the button setup I Currently have..

alt text

and this is kind of what it looks like..

alt text

buttonssetup.jpg (76.5 kB)
selection-of-barracks.jpg (316.0 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

29 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

NetworkServer.Spawn() only on Server (with registered prefabs) [Unity 5.2.3f1] 0 Answers

Can i add a time var to my spawnInterval for increasing spawing over time? 0 Answers

Changing The Size Of NetworkManagerHUD 0 Answers

End Game (Stop spawning) with OnTriggerEnter or OnCollisionEnter? 0 Answers

Problem instantiating objects one after another with mouse click 1 Answer


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