Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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
1
Question by Slasmir · Feb 09, 2012 at 10:26 PM · buttonsdoors

Door opener

Hello i am having a game where diferent buttons are going to open different doors.

The code for the button use is:

 var ButtonNr     : int;
 
 //Private Variables 
 var isOn : boolean = false;
 function Update () 
 {
     if(isOn)
     {
         //OpenDoor(ButtonNr);
     }
 }
 
 public function UseButton()
 {
     if(isOn)
     {
         isOn = false;
         renderer.material.color = Color.blue;
     }
     
     else if(!isOn)
     {
         isOn = true;
         renderer.material.color = Color.green;
     }
     print(isOn);
 }


As you can see i have commented out OpenDoor(ButtonNr) as i dont know how to call it in a diferent script. the other script looks as this:

 var DoorOpen    : boolean    =    false;
 var DoorNr        : int;
 function OpenDoor(nr : int)
 {
     if( nr == DoorNr && !DoorOpen)
     {
         Destroy(gameObject);
     }
 }

i need it to test all of the doors if there button have been switch on is there a way to individualy check all doors ?

thanks for your time and i hope you will 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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by aldonaletto · Feb 09, 2012 at 11:52 PM

There are several ways to do that, but I would do the following:
1- Create an empty object, call it "Doors" and reset its position and rotation;
2- Child all doors to this object;
3- Modify the button script like this:

var ButtonNr : int; static var theDoors: GameObject; // reference to "Doors" object

function Start(){ // first button executing Start assign theDoors: if (!theDoors) theDoors = GameObject.Find("Doors"); }

//Private Variables var isOn : boolean = false; function Update () { if(isOn) { // call the function OpenDoor(ButtonNr) in all children of "Doors" theDoors.BroadcastMessage("OpenDoor", ButtonNr, SendMessageOptions.DontRequireReceiver); } }

public function UseButton() { if(isOn) { isOn = false; renderer.material.color = Color.blue; }

 else if(!isOn)
 {
    isOn = true;
    renderer.material.color = Color.green;
 }
 print(isOn);

}

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

Help with Scripting (Boolean) 1 Answer

Script to make an enemy follow the player when they trigger a door? 0 Answers

ignore left mouse button click in game when clicking on gui buttons 1 Answer

Multiple Doors and Buttons 0 Answers

How to link gui buttons to seperate scripts? 1 Answer


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