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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Christoff · May 09, 2011 at 03:18 PM · doorlock

Help scripting Combination lock/ pressure plates

OK to keep things simple, on my game level im going to have 5 pressure plates on the floor.

To keep things simple lets name them A,B,C,D,E.

I want to make the player press them in a certain order for a door to open or an animation play.

For example i want the pressure plates to be pressed in B,A,D,E,C order but i want them to reset if the user inputs them in the wrong order. What is the simplest way to do this?

Can anyone help me write the correct scripting.

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

· Add your reply
  • Sort: 
avatar image
0
Wiki

Answer by WilsonS · May 09, 2011 at 05:40 PM

You are going to need two scripts. One to process individual pressure plates, and one to detect finished condition. As for requiring a specific order, just put the pressure plate objects into the control array in the desired order with the editors drag and drop.The following is some untested pseudo code to get you going in the right direction.

PressurePlate.cs ////////////////////////////////////////////////////////////

using UnityEngine; using System.Collections;

public class PressurePlate: MonoBehaviour { public bool isDown;

void Start(){ isDown = false; // default to not down }

void OnTriggerEnter( Collider other){ // only set as down if a game object named "Player" has collided with me if(other.name == "Player") isDown = true; }

} /////////////////////////////////////////////////////////

PressurePlateCtrl.cs /////////////////////////////////////////////////////////

using UnityEngine; using System.Collections;

public class PressurePlateCtrl :MonoBehaviour { public PressurePlate[] myPlates; public Animation myFinal; // door opening object animation

void Start(){ ResetPlates(); myFinal.Stop(); }

void ResetPlates (){ for(int itor =0; itor < myPlates.Length; itor++){ myPlates[itor].isDown = false; } }

void Update(){ // dont process if myFinal animation has already run or is not attached if(myFinal == null) return; bool swapFlag = true;

   for(int itor = 0; itor &lt; &lt; myPlates.Length; itor++){
      if(swapFlag){
         if(myPlates[itor].isDown == false) swapFlag = false;
      }else{
         if(myPlates[itor].isDown == true){
            Reset(); // true encountered after 1 false indicates out of order
         }
      }
   }
   // if swapFlag is true here, that means all plates are down in the correct order
   if(swapFlag == true){
      myFinal.Play();
  myFinal = null; // break connection so we dont reprocess
   }  

} } ///////////////////////////////////////////////////////

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

No one has followed this question yet.

Related Questions

Pick up key and unlock a locked door 1 Answer

Door key code 2 Answers

Need help with my animation script 2 Answers

door script problems 2 Answers

Door script lag with rotation (Quaternion.slerp ?) 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