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 pouya90 · Feb 28, 2015 at 01:42 PM · getcomponentpausesetactivebool

check if the bool is true from other script c#

hi . i want to make a popup window when the character die with UI . i made a pause bool in character script and it works . in canvas script i want to say when pause is true ( or time.deltatime = 0 ) show the canvas . i wrote this in canvas script but it doesn't work .

 void Start () 
     {
         gameObject.SetActive (false);
 
     }
 void Update () 
     {
         if(GameObject.Find ("ball").GetComponent<ball_script>().pause)
         {
             gameObject.SetActive (true);
                 }
     }
 }

and this is part of the script for my character:

 public bool pause = false;
 
 void Update()
     {
         if(dead)
         {
             deathCooldown -= Time.deltaTime;
 
             if(deathCooldown <= 0)
             {
                 if(pause = true )
                 {
                     Time.timeScale = 0;
                                 }
                }
             }
         }
 
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 pouya90 · Feb 28, 2015 at 06:44 PM 0
Share

ok i have tried other things but i always get some error . what should i write in my character script to find the canvas and set active to true ?

I have written this in my character script but gives error :

                 if(pause = true )
                 {
                     Time.timeScale = 0;
                     GameObject.Find ("Canvas").GetComponent<popupDead>().gameObject.SetActive(true);
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by NoseKills · Feb 28, 2015 at 01:46 PM

If you do setActive(false) in Start(), Update is not automatically being called. You have to keep the UI GameObject active but prevent drawing the UI with another boolean or something.

Or you could call canvasObject.setActive(true) from your character script when he dies.

Comment
Add comment · Show 5 · 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 pouya90 · Feb 28, 2015 at 06:43 PM 0
Share

what should i write in my character script to find my canvas and set activer to true . right now i wrote this but gives error :

                 if(pause = true )
                 {
                     Time.timeScale = 0;
                     GameObject.Find ("Canvas").GetComponent<popupDead>().gameObject.SetActive(true);
 }
avatar image DiegoSLTS · Feb 28, 2015 at 06:59 PM 0
Share

Why not just have a reference to the canvas set in the inspector? This way you can use the same code to display activate different things.

Finding objects by name is slow, and it can create hard to track bugs if anyone changes the name of the objects (something really common).

If you still want to search for the Canvas, doing:

 GameObject.Find ("Canvas").GetComponent<popupDead>().gameObject

is redundant, "GameObject.Find ("Canvas")" already returns the object, you don't need to get a component and then the gameObject for that component.

avatar image pouya90 · Feb 28, 2015 at 07:11 PM 0
Share

ok thanks , can you help me with making a refrence to the canvas set in the inspector , because it's hours i'm trying and i always get an error .

avatar image NoseKills · Feb 28, 2015 at 08:21 PM 0
Share

It would help if u told us what the error was. At least you seem to be trying to set pause to true inside an if-clause: if (pause = true), you probably want it to be a boolean check: if (pause == true) or just if (pause) which works as well. Otherwise I can't spot anything obvious if "Canvas" and popupDead are spelled correctly and that script is attached to that gameObject when the call is made.

avatar image pouya90 · Mar 01, 2015 at 06:11 AM 0
Share

the pause is working very good ,the problem is only in canvas when i say setactiv to false in start then in update it will not check my if (pause = true) . what is your suggestion to write insted of setactive to false ? void Start () { gameObject.SetActive (false);

     }
     void Update () 
     {
         if(GameObject.Find ("ball").GetComponent<ball_script>().pause)
         {
             Debug.Log("it works");
     }
 }

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Gameobject.SetActive not working on Android? 1 Answer

Why does this bool get reset? 1 Answer

gameObject.GetComponent("Script").enabled = true not working 5 Answers

How do I change a clicked on GameObjects variable when a boolean (Next Turn) is true? 1 Answer

Ok so im trying to get a string's name from another script to enable (SetActive) a certain gameObject in the scene (the player); however I keep getting errors and i have no idea what to do?? any help??? 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