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 /
This question was closed Aug 31, 2018 at 03:27 AM by RX187 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by RX187 · Aug 31, 2018 at 12:05 AM · instantiatebuildingrtsinstantiate prefabhowto

Multiple Buildings Placement

Hello. I have a building system in place and buttons that act like the building image and etc. When I press the button, the building instantiates correctly, it can be placed correctly, everything works fine.


However when the building is placed then that's it, I cannot place the building again unless I press the button again and I know it does that because when the building is placed the prefab holder is set to null.


Here are two code snaps:


This one is used to place the building:

 public void PlaceFixture()
     {
         if (Input.GetMouseButtonDown(0))
         {
             fixtureToPlace.layer = 0;
             surface.BuildNavMesh();
             fixtureToPlace = null;
             isPlaced = true;
         }
     }
 
 private void Update()
     {
         if(isBuilding)
         {
             Time.timeScale = 0;
             visualGrid.SetActive(true);
             MoveObjectToMousePosition();
             RotateObject();
             PlaceFixture();
             
             if (Input.GetMouseButtonDown(1))
             {
                 Destroy(fixtureToPlace);
                 isPlaced = false;
                 fixtureToPlace = null;
             }
         }
     }

And this is the one used for the button:

 public void PlaceFixture()
         {
             buildingSystem.isBuilding = true;
             buildingSystem.fixtureToPlace = Instantiate(modelPrefab);
             modelPrefab.name = "Shelf";
         }

The script above is used in a prefab that gets it's information from a scriptable object database and I cannot simply simply say in the first script to just repeat that because it needs to search for that specific item in the list.


My question is what can I do/change to instantiate another building immediately after the first one is placed without clicking the button multiple times?


Thanks in advance!

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

  • Sort: 
avatar image
0
Best Answer

Answer by RX187 · Aug 31, 2018 at 03:26 AM

Eh, nevermind, I fixed it quite easily:

 if(isPlaced)
         {
             isPlaced = false;
             fixtureToPlace = Instantiate(fixtureToPlace);
              }

And in the script that has the button

 public void PlaceFixture()
     {
         buildingSystem.isBuilding = true;
         buildingSystem.fixtureToPlace = Instantiate(modelPrefab);
         buildingSystem.fixtureToPlace.layer = 2;
         modelPrefab.name = "Shelf";
     }

Just in case someone needs it.

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

Follow this Question

Answers Answers and Comments

111 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

Related Questions

RTS Building Structures - How to have building follow my cursor until I click and place it on the grounds? 2 Answers

Spawning multiple objects in same area without intersecting each other 0 Answers

How to instantiate a prefab each time I click the UI button? (getting it only once when I click the button) 4 Answers

Game works when i use "build and run" and in the game tab, but not when i build it as an EXE 0 Answers

How to manipulate a variable of a prefab script (instantiated) while the game is runnning . 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