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 /
avatar image
0
Question by Digital-Phantom · Sep 25, 2017 at 03:50 PM · gameobjecttransformboolspawnpoints

How to Spawn Object at next Empty Location

I have a very simple script that spawns an item when the player mouse clicks a button. Now I want to have multiple items that spawn in the next empty slot (basically like an inventory system, if one slot is full it automatically uses the next slot)

 public class spawnItem : MonoBehaviour
 {
 
     public GameObject newItem;
     public Transform slotOne;
 
     void OnMouseDown()
     {
         Instantiate(newItem, slotOne.position, slotOne.rotation);
     }
 }

I now have 3 empty slots(spawn points) how do I get it to recognise that the first one is full and add the item to next slot? I'm guessing I need to use a bool, starting at false, then true one the object has been instantiated. Am I going to need a script on each of the slot transforms to tell this script they are either empty or full?

Any help greatly appreciated.

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 hexagonius · Sep 25, 2017 at 04:04 PM 0
Share

Ins$$anonymous$$d of an unnecessary bool, if the slot is not null, it's full, right?
Depending on your system you could have an index that moves forward whenever a slot gets filled, if the whole thing is consecutive.
If not, two lists, one with available, one with filled slots could be a solution, where you live slots around.

1 Reply

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

Answer by Tony_T · Sep 25, 2017 at 04:19 PM

Your thinking is correct if you want it to be like an inventory because you may want to check if a slot is empty more than once. You can use bools like you said yourself to check if the slot is emtpy.

First you need to use this variable type since you have multiple spawn points:

 public Transform[] Slots;

Then to check if a slot is empty you can use bools for every slot like this:

     public bool Slot1; //false = empty, true = not empty
 
     If (Slot1 == false)
     {
     Instantiate(newItem, Slots[0].position, Slots[0].rotation);
     }
     else if (Slot1 == true)
     {
      //do nothing
      }
Comment
Add comment · Show 1 · 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 Digital-Phantom · Sep 27, 2017 at 04:54 PM 0
Share

Sorry for delayed response. Yep that worked. Thanks

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

112 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 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 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 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

Need insight on strange (simple) 2D object transform bug 0 Answers

how can i move another gameobject from a single script? 1 Answer

Can't jump in diagonal 1 Answer

Convert Transform to Gameobject 1 Answer

Can You Convert a Transform into an Image? 2 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