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 Magnet_man16 · Feb 22, 2014 at 08:03 PM · buttonsdoorsthankspublic static

Help with Scripting (Boolean)

I have a public static bool open; which is set weather the door is open or not. This is required as two gameobjects use the script and this makes sure they both know if the doors open or not. It works.

However when I have multiple doors they all think they are either open or closed. Is there any way I can give the doors ID's so in the inspector I could in each button put for e.g. 1. And then for another door and buttons 0.

Theoretically it would work, however I don't know how to implement something like this. Im a expert in C# but that with software and I'm relativity new to unity.

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
Best Answer

Answer by getyour411 · Feb 22, 2014 at 08:05 PM

give the gameobjects a script with a public variable like

public int doorID;

and then assign it in the inspector. Don't use a static for that.

Comment
Add comment · Show 7 · 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 Magnet_man16 · Feb 22, 2014 at 09:58 PM 0
Share

I've done that but how would I implement that as currently i know for example Door1 open/close ect but theyc still dont know their individual status.

Currently its like Door_F open = true; Door_R open = true; Door_L = true;

It needs to be Door_F open = true; Door_R open = false; Door_R open = true;

For example. So each door knows if its open or not. But as the script runs on two gameobjects this is proving difficult.

Here are my doors Ones Open and the Other Closed. As I opened one they both think they're open so when the closed door is opened via the button it closes... as it has the same static bool.

Note im using animations to move parts of a .fbx model I made.

alt text

avatar image getyour411 · Feb 22, 2014 at 10:47 PM 0
Share

You're an expert in C#? I don't know what you are asking anymore tbh, using a static as an open/closed flag on multiple doors makes no sense. "They still don't know their individual status" - no clue how to interpret that. If they have a bool setting for open/close, how do they not know their status? Are you really just asking "How do I get the bool value on DoorA (b, c, doesn't matter) from two or more scripts on other Gameobjects?

Such as

 Door.cs
 public bool doorState;
 
 Script1
 ...GetComponent<Door>().doorState
 
 Script 2
 ...GetComponent<Door>().doorState
 
 now both Scripts 1 and 2 'know' the doorState
avatar image Magnet_man16 · Feb 22, 2014 at 10:57 PM 0
Share

I have a game object (the junction you see in the image. Its one game object / model. The doors are separate things in this model so can move. I animated a open and closing animation. When the user presses the button (white) the doors need to open if closed and visa versa. The way it knows which doors to open is due to it looking for the Front, Left or Right door animation (corridor splits 3 ways).

Currently the doors don't know their state if you use the button on the other side as using static all doors have the same open value.

If I dont use static each button treats the door individually and you may end up running the open animation several times due to all the buttons starting off with thinking the doors not open. and when another button opens it this button doesn't know that.

The only solution would be to read the variable of the component on the button on the other side of the wall. As I'm new to unity im not sure if this is possible.

I made this it may explain my issue. alt text Thanks, $$anonymous$$.

avatar image Magnet_man16 · Feb 22, 2014 at 11:17 PM 0
Share

Ok I'll give it a go

avatar image Magnet_man16 · Feb 22, 2014 at 11:27 PM 0
Share

The value is carried but as both are getting the doors value from each other they always both are false. I will work on finding a way around this.

Show more comments

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

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

rigidbody2D.velocity.y always returns 0 2 Answers

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

How to make buttons that will move an object to a certain point based on the characters choice? 0 Answers

Monodevelopement not responding? 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