Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 ryand444 · Jun 04, 2012 at 03:31 PM · triggerswitchdoordoors

Multi Switch Door

hi, im fairly new to unity i currently creating a basic fps project with a simple two way door system i.e a switch that destroys its assigned object im just wondering if theirs any possible way to make it so that the player has to activate multiple switches in order to open the door or destroy it im not looking for coding per say however im just looking to be pushed in the right direction. any help will be greatly appreciated.

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

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by You! · Jun 04, 2012 at 03:39 PM

You need to create a script (attached to the door) with as many public booleans as there are switches (or, if you rather, an public integer originally set to zero). Each time a switch is activated, change one of the bools to true (or add one to the integer) using the formula [scriptname].[varname] in a separate script. Lastly, use an if statement to check to see that all of the bools are true (or that the integer is equal to the number of switches). Then, either destroy the door ("Destroy(gameObject)") or activate an animation for the door (Animation.Play("/name of animation/")).

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
0

Answer by ryand444 · Jun 04, 2012 at 03:44 PM

thank you very much appreciated do you know of any tutorials or guides which could help under stand the process further since your explanation was good however i need some examples to help me put it into my context and i apologies if this is asking to much.

Comment
Add comment · Show 3 · 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 AlucardJay · Jun 04, 2012 at 05:14 PM 1
Share

Attach this script to a door :

 // Door_Opener_Script

 public var Button1 : Button_Script;
 public var Button2 : Button_Script;

 function Update()
 {
     if (Button1.IsPressed && Button2.IsPressed)
     {
         // Open the Door
         Destroy (gameObject);
     }
 }


On 2 buttons, attach this script to each :

 // Button_Script

 public var IsPressed : boolean = false;
 private var timer : float = 0.0;
 private var timerReset : float = 3.0;

 function OnTriggerEnter( otherCol : Collider )
 {
     IsPressed = true;
     timer = timerReset;
 }

 function Update()
 {
     if (timer < 0)
     {
         IsPressed = false;
         timer = 0;
     }
     else
     {
         timer -= Time.deltaTime;
     }
 }

Then drag-and-drop each button into the Door Inspector (Button1 & Button2)

When anything activates the trigger on a button, the button is set to true. (i have included a timer, so the button starts counting down, then resets to false). The script on the door reads each button script and finds out if IsPressed is set to true. If so, open the door. This is just a quick example and not the best explaination, but let me know if you have any qns on this idea =]

EDIT : I have put a Destroy (gameObject); call where you asked. But you could do many things at this line, play an animation, disable a rigidbody, etc.

Here is the Unity Script Reference for Object.Destroy : http://unity3d.com/support/documentation/ScriptReference/Object.Destroy.html

and OnTriggerEnter : http://unity3d.com/support/documentation/ScriptReference/Collider.OnTriggerEnter.html

avatar image ryand444 · Jun 04, 2012 at 05:21 PM 0
Share

thank you very much this is very helpful i will contact you if i have any more questions however this is exactly what i was looking for once again thanks

avatar image AlucardJay · Jun 05, 2012 at 01:44 AM 1
Share

" i do have one more question how would i go about destroying the door after all the switches have been activated as there is a { open door } in the script you provided but i just wouldnt know how to wright the object being destroyed "

I have edited my comment.

avatar image
0

Answer by ryand444 · Jun 04, 2012 at 06:40 PM

i do have one more question how would i go about destroying the door after all the switches have been activated as there is a { open door } in the script you provided but i just wouldnt know how to wright the object being destroyed

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 ryand444 · Jun 07, 2012 at 08:32 PM

i ma sorry to bother once again but i would like to know if there is any way of showing the time limit maybe as a GUI to the player once again i don't expect a solid answer a budge in the right direction would be helpful. thanks

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 You! · Jun 07, 2012 at 09:47 PM 0
Share

This should really really really really be a comment. Please convert it to one so that we know who you are talking to!

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

Sliding door animation question. 3 Answers

Go through door, by loading next scene, with key-press 1 Answer

I am trying to make a door, when using this script nothing happens. 0 Answers

Opening door with the same key? 1 Answer

Sliding Door question 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