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 /
This question was closed May 01, 2015 at 06:34 PM by Razputin for the following reason:

Other

avatar image
0
Question by Razputin · May 01, 2015 at 05:05 PM · booleanboolaccessingnon-static

Accessing non-static bools across scripts

I need to figure out which way my player is facing which I have in the PlayerAnimator Script using this

         if(rigidbody.velocity.x > 0.25f && direction == false){
             direction = true;
         }
         if(rigidbody.velocity.x < -0.25f && direction == true){
             direction = false;
         }

I need to put the direction boolean into another script called Death1. I could just copy paste the above code since it's not very long, but I figure I might as well learn the proper way to do it.

The PlayerAnimator is actually destroyed prior to Death1 being instantiated.

When the Players health hits 0 hes destroyed and replaced with a prefab for that death. For example if hes killed by a mine hes destroyed and MineDeath is instantiated. Can I still get the Direction even after PlayerAnimator is no longer in the scene?

Closed: Im just gonna use playerprefs

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

2 Replies

  • Sort: 
avatar image
0

Answer by Sessional · May 01, 2015 at 05:10 PM

You are going to want to be using a GetComponenet() call. As long as the thing you are accessing is public you'll be able to reach it.

I'm assuming these two scripts will be on the same object?

Comment
Add comment · Show 2 · 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 Razputin · May 01, 2015 at 05:18 PM 0
Share

They're not on the same object. Can I still be using get component? The gameobject holding PlayerAnimator is destroyed before death1 exists.

avatar image Sessional · May 01, 2015 at 05:33 PM 0
Share

If that is the case you can not access that variable variable any more, because that script (PlayerAnimtor) would have been destroyed before death1 exists.

You could try disabling PlayerAnimator before hand and getting the variable and then destroying PlayerAnimator after that.

avatar image
0

Answer by hbalint1 · May 01, 2015 at 05:11 PM

just make the direction to public. don't need to be static.

 public bool direction;

then you can search for the object and script, which contains this.

 GameObject.Find("TheObjectHavingTheScript").GetComponent<TheScriptContainsDirection>().direction;
Comment
Add comment · Show 2 · 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 Razputin · May 01, 2015 at 05:21 PM 0
Share

The gameobject that has PlayerAnimator attached is destroyed Prior to the death1 script being in the scene. I just added more info to the question.

avatar image hbalint1 · May 01, 2015 at 05:30 PM 0
Share

after you destroy the playeranimator of course you can't get any information from it. But if you get the last direction value and store it in the Death1 script befor you destroy the object, you can use it. But you will lose control over the direction change.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

How to change bool values from one controlling script to a receiver? 1 Answer

How to add a Sprite Rollover Image using a Button Array 0 Answers

Set a Bool Through Function 1 Answer

Unity UI Button Switch Bool? 2 Answers

Unable to set boolean to true 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