• Unity
  • Services
  • Made with Unity
  • Learn
  • 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
  • Forums
  • Answers
  • Feedback
  • Issue Tracker
  • Blog
  • Evangelists
  • User Groups

Navigation

  • Home
  • Unity
  • Industries
  • Made with Unity
  • Learn
  • Community
    • Forums
    • Answers
    • Feedback
    • Issue Tracker
    • Blog
    • Evangelists
    • User Groups
  • Get Unity
  • Asset Store

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

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

Instantiate buttons , each with a unique positioning 2 Answers

Accessing variable in a specific instance of a prefab 1 Answer

RTS building placement collision problem C# 1 Answer

RTS building snap to grid 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges