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
0
Question by nongenre · Jun 09, 2012 at 05:29 AM · prefabsinstantiation

Using a Master Control Script w/Instantiated prefabs & multiple scenes?

I've dabbled in Unity with several mini-projects, and am now attempting something with a little more structure. I'm realizing that I don't know the best way to set up a Master Control script that will work with instantiated objects and in multiple scenes.

My project has two scenes - one which is an empty game map, and another which is a warehouse where my prefabs live.

My game has turret towers which the player can place (instantiate as prefabs) around the map. Each of these towers has a script for tracking the mouse and firing at a target/clicked object.

I'm using a master control script assigned to a dummy object in the scene to handle the raycast for targeting, as well as a boolean which toggles whether turrets should be firing or not. This is also where I'll later track things like game states or score, etc. This seems like a good idea for performance and organizational reasons.

The turrets have their own script, with a variable which points at the Master Control script. This works great if I pre-place the turret in my scene and manually point that variable at a dummy with the MC Script on it. When I try to make this systemic, however, I run into two problems:

1) I don't know where Master Control Script should actually live. As mentioned: I have it currently on a dummy object in the scene, and that script includes DontDestroyOnLoad(transform.gameObject); in the Awake() function, but I'm not sure this actually allows me to have one script which will persist across all scenes. Right now I have to pre-place my turrets in each scene, as well as place a dummy with the MCS in each scene (and point each turret script to that dummy).

2) Probably related to the above, I cannot assign the variable on my turret prefab to point at the object with the MCS.

I think this boils down to me not quite understanding the best way to use prefabs. Would love to hear some input on how to best structure things.

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 Fattie · Jun 09, 2012 at 08:21 AM 0
Share

"Right now I have to pre-place my turrets in each scene..." etc.

FWIW that sounds utterly normal and good.

"I think this boils down to me not quite understanding the best way to use prefabs" just purely FWIW I dislike prefabs and think they are silly, confusing and unhelpful. They're greatest value is nothing more than a convenient way to move large groups of stuff from the art department to the program$$anonymous$$g department, ie, they help you figure out "what is used" on some object. So if you don't like prefabs, "give them the arse over the side," as they say on fishing boats in the North!!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Attacking a Prefab 1 Answer

"Type mismatch" in play mode after doing member assignment 1 Answer

Null prefabs? 1 Answer

How to make On Click() work with prefabs? 1 Answer

Is it possible to prevent certain components from being used in AssetBundles? 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