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!
'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);
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. :)
Your answer

Follow this Question
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