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 KamikazeCoPilot · Oct 04, 2015 at 09:15 PM · referencingbooleans

Referencing a Boolean from another script

I have two different scripts. The first script is a simple button that is looking for a clicked. And if it is clicked, to set a boolean that is within it.

public class Seated : MonoBehaviour { public bool isSeated=false; public void clicked() { isSeated = true; Debug.Log("Was clicked."); } }

Now, the error I am not getting anything as a "void" cannot return anything. When I change the clicked() to a bool, I can't get it to work properly with the inspector to show that isSeated has been clicked.

When referencing it on the other script, it looks like:

  •  private Seated seated;
       seated = GetComponent<Seated>();
       if(seated.isSeated == true && Drinks.drinksOrdered != true||Drinks.drinksOrdered != false && seated.isSeated == false)
         {
             timer += Time.deltaTime * 1;
         }
    

Where am I going wrong? I am sorry if I have asked for this incorrectly. I appreciate the help, guys && gals.

Thanks!

Comment
Add comment · Show 1
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 meat5000 ♦ · Oct 04, 2015 at 09:52 PM 0
Share

'void' only affects the return type.

This will not affect variables that are declared outside of that function which can be altered as normal and your debug.log will operate as normal.

To access the Clicked function:

seated.Clicked(); should work.

Dont forget you can add an argument INTO that function despite it being void.

 public void clicked(bool seating) 
 {
     //seating variable injected from other script
 }

Called with:

 seated.Clicked(boolYouWantToSend);

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by KamikazeCoPilot · Oct 07, 2015 at 02:21 AM

@meat5000, I am sorry that I haven't gotten back to you sooner. I appreciate the feedback. This did help a lot. I didn't think that something as simple as a return; would have fixed it. Again, it is appreciated. :)

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

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

Related Questions

Copied GameObject affected by the original GameObject 1 Answer

Building a Face Generator, need to destroy previous instance after pressing key a second time 0 Answers

How to protect SaveLoad script from failing? 1 Answer

null reference help. i fundamentally dont understand. 1 Answer

Where to store province/tile information for a strategy game? 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