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 krearthur · Oct 08, 2015 at 03:31 PM · optimizationgameobjectsbehaviour

What is the best way to handle behaviour of many similar objects?

Hi,
I have like 100 doors in one scene and I need to write a script to open and close them. Should I attach 100 scripts to the objects or is it better to attach 1 script to the player and ask in the collision event if it is a door and do the logic there?

I want to automatically close the doors after 5 seconds, so I have to have some list of door objects in the player script and check every door in this list to close it after 5 secs. But this extra door handling is still better than attaching simple door-scripts to each door I guess?

Thanks for your help::)

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Dave-Carlile · Oct 08, 2015 at 04:00 PM

You have to keep a list of objects somewhere right? Why not just use Unity's built-in list of objects and attach the script to each of them? Presumably that would be part of a prefab.

The code itself isn't duplicated 100 times - just any data that's part of your script class. This data is state you'd have to maintain yourself (your list of objects, the timers, etc.) so it makes sense to keep that data in the door script and attach it to the doors.

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
avatar image
0

Answer by llndprkr · Nov 09, 2015 at 08:23 AM

@abeing This is exactly what the Prefab feature is for. It allows you to create a single master object and clone it around your scene. Whenever you edit the prefab (master object), the clones are automatically updated. The clones also have a button in their Inspector tab that allows you to send changes to a clone back to the master--and out to all other clones.

Prefabs are explained starting at 4:16 in this video: http://unity3d.com/learn/tutorials/projects/roll-a-ball/creating-collectables?playlist=17141

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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Resources used by inactive Game Objects, many weapons 0 Answers

Weird gameobjects creating from nothing? 0 Answers

Accessing gameObject through playerscript with button attached to the playerscript C# 0 Answers

Problem with Dictionary.Remove 1 Answer

Hi, I have some script that is attached to an object so that it isn't destroyed as you play through level 1, level 2, level 3 and so on. However I want this object to be destroyed when the player click the menu screen 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