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 easilyBaffled · Jul 09, 2012 at 06:16 PM · gameobjectboolean

Cannot Locate Boolean in different script

Alright here is the problem, I am trying to get the moved boolean in one script so I can use it in another script. I've declared it public var moved : boolean = false; and it even shows up with the little check box in the inspector. But then I try to access it from a script attached to a different game object, like this:

 Physics.Raycast(transform.position, Vector3.right, hit, 3.0);
 if(hit.collider.gameObject.tag.Contains("tile")){
 var tile = GameObject.FindGameObjectWithTag(hit.collider.gameObject.tag);
 Debug.Log(tile.moved);

I get "Assets/Script/Shuffle.js(29,48): BCE0019: 'moved' is not a member of 'UnityEngine.GameObject'."

and I've tried Debug.Log(tile.GetComponent("Slider").moved); Slider.js being the name of the first script.

So anyone know why it cant be found?

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

4 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by easilyBaffled · Jul 09, 2012 at 07:19 PM

Thank you everyone for you suggestions. Unfortunately, as it usually is, the problem was just a stupid mistake. I had tile.GetComponent("Slider").moved when the quotes were unnecessary its just tile.GetComponent(Slider).moved

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

Answer by Screwworkn · Jul 09, 2012 at 07:03 PM

You are at the gameobject and you need to reference the script component that is on the game object. Here is the idea in C#.

 //Get GameObject
 GameObject newBall = (GameObject)Instantiate (Ball);
 //Get ScriptObject from the GameObject
 BallScript bs = (BallScript)newBall.GetComponent (typeof(BallScript));
 //You can now access properties.
 bs.BallSpeed = 10;
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
avatar image
0

Answer by Ingen · Jul 09, 2012 at 07:03 PM

missing "" for error-"Assets/Script/Shuffle.js(29,48)...'moved' is not a member... Debug.Log("tile.moved");

take a look at this to take a function in another script

it work, just have another problem about the animation

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

Answer by Eric5h5 · Jul 09, 2012 at 06:42 PM

You need to use GetComponent with the GameObject that's returned by FindGameObjectWithTag. The variable is part of the script component, not the GameObject.

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 easilyBaffled · Jul 09, 2012 at 06:53 PM 0
Share

That's what I am doing, I assigned the result of FindGameObjectWithTag to tile, then tried to get it from tile. Just to make sure I tried (GameObject.FindGameObjectWithTag(hit.collider.gameObject.tag).GetComponent("Slider").moved); And it still won't find it. Or am I just missing something completely?

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Disable / enable script 2 Answers

Turning a menu on and off onclick in hololens 0 Answers

Bool based on objects existing not changing. 2 Answers

Boolean Not Changing 1 Answer

Unable to show gameobjects at specific timing 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