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 Addyarb · Jul 07, 2014 at 10:15 PM · reference

Bool from referenced script not updating?

Hi there,

I've been playing with this for about a week off-and-on, and I can't seem to properly reference a bool I've created in one script to another.

The debug.log text in the first script (NPC_Dialog) appears, and the bools work fine. However, the referenced bool from the second script, while recognized as a referenced bool, does not change or present it's debug.log text to the console.

Thanks for the help! Hope it's something simple, as I've set up many instances in my game to be referenced in such a way.

Addyarb

 **///Script 1 (NPC_Dialog)**
         void OnGUI () {
                     GUI.skin = NecroGUI;
                     GUILayout.BeginArea (new Rect (Screen.width / 2, Screen.height / 2, 400, 400));
                     if (DisplayDialog && !ActivateQuest) {
 
                         GUILayout.Label (Questions [0]);
                         GUILayout.Label (Questions [1]);
                         if (GUILayout.Button (answerButtons [0])) {
                                 exclamationPointBobbing = true;
                 Debug.Log ("Exclamation Bool Set TO true");
                                 toggleGUI = true;
                                 ActivateQuest = true;
                                 hasDoneQuest = false;
                                 DisplayDialog = false;
                                 instructions = true;
             
 
                         }
                         if (GUILayout.Button (answerButtons [1])) {
                                 DisplayDialog = false;
 
                         }
                 }
                 if (DisplayDialog && ActivateQuest && hasDoneQuest == true) {
                         GUILayout.Label (Questions [2]);
                         if (GUILayout.Button (answerButtons [2])) {
                                 DisplayDialog = false;
                 exclamationPointBobbing = false;
 
                         }
 
                 }
                 GUILayout.EndArea ();
 
 
                 if (ActivateQuest && toggleGUI && instructions == true) {
 
                         
                         connectionWindowRect = GUILayout.Window (0, connectionWindowRect, InstructionsWIndow, "Quest: Lost Locket"); 
 
                 }

///Script 2.. "Exclamation Mark Enable"

 using UnityEngine;
 using System.Collections;
 
 public class QuestPointEnable : MonoBehaviour {
 
     public NPC_Dialog npc;
     public Transform  exclamationPoint;
     // Use this for initialization
     void Start () {
         exclamationPoint = transform;
 
         npc = GameObject.Find("NPC").GetComponent<NPC_Dialog>();
 
     }
     
     // Update is called once per frame
     void Update () {
         if (npc.exclamationPointBobbing = true) {
             Debug.Log ("Bool Triggered For QuestPoint Enabled");
                         exclamationPoint.renderer.enabled = true;
                 }
 
                 }
 
 }

Comment
Add comment · Show 4
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 MarioAGOrdiano · Jul 07, 2014 at 10:29 PM 0
Share

in update on script2 you are not checking the variable but assigning it.

Remeber the == operator is for checking the = operator is for chanigng values.

also; do you have more than one npc on the scene?

avatar image Addyarb · Jul 07, 2014 at 11:39 PM 0
Share

I do have more than one NPC, yes. Well, I have a rough copy of the script to use as a different NPC dialog. I will check the update right now, thanks!

avatar image Addyarb · Jul 07, 2014 at 11:45 PM 0
Share

Also, can you elaborate on which = to change? (what line?) From what you wrote, I'm guessing the first one, but I tried that and it made no difference so far. I tried to change the second one, but I got an error: (20,90): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement

avatar image Addyarb · Jul 08, 2014 at 02:59 AM 0
Share

Update: I've tried referencing the transform of my gameObject "Exclamation point" within the first script itself, but still no luck. I'd be just as happy if I could make the thing enable/disable in response to a bool change, but I'm having no luck at all.

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Kiwasi · Jul 07, 2014 at 11:57 PM

Change line 18 of the second script to the following. Otherwise you will be changing the value instead of checking it. Has caught me out once or twice...

 if (npc.exclamationPointBobbing == true) {

One way to avoid this problem is to use properties. You can change your variable declaration to the following, which means that only the one script can change it, but any script can read it.

 public bool exclamationPointBobbing {get; private set;}
Comment
Add comment · Show 1 · 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 Addyarb · Jul 08, 2014 at 12:10 AM 0
Share

That edit doesn't seem to solve my issue I'm afraid. I completely see what you mean now about the == vs. =, but the bool is still not being read as true on the second script, because the debug text nor the transform become enabled.

avatar image
0

Answer by Addyarb · Jul 08, 2014 at 03:58 AM

The (now obvious) reason it wasn't working is because the transform of the object containing the script that was referencing the bool of the other script was disabled. (I wanted to enable it via a script that was contained within the object). A stupid mistake, but once I enabled the object and switched the transform.enable to mesh renderer.enable, it worked just fine.

Thanks for the help! Hope this saves someone like me a lot of trouble one day.

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

23 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

Related Questions

Reference creator of gameObject 1 Answer

Destroying Prefab Also Destroys Prefab Reference 1 Answer

How to have an instance only reference its parent 1 Answer

How to disable referenced Prefabs being preallocated in memory?? 0 Answers

How to resolve script references in scene bundles from dynamically loaded assemblies? 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