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 IMTRIGGERHAPPY9 · Oct 31, 2011 at 03:23 AM · variablegridcube

one var that is local in multiple objects still used by other scripts?

so i have multiple objects( Grid of cubes) that i want to have a variable called canUse; what i am asking is if i can have this one variable be local to the gameObject, but then acces each variable in another script?

Comment
Add comment · Show 2
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 syclamoth · Oct 31, 2011 at 03:55 AM 0
Share

I don't understand, you want it to be local, but you also want others to be able to see it? I'm sure what you want to do is possible, but I need you to explain it a bit better.

avatar image IMTRIGGERHAPPY9 · Nov 05, 2011 at 04:56 AM 0
Share

ps anybody who looks at this question it was a stupid question as my script just wasn't functioning as i thought it would. variables are assigned to individual gameObjects as the below answers have said sorry about that.

1 Reply

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

Answer by gfr · Oct 31, 2011 at 04:40 AM

If you're raycasting for another object, you can get the hit gameobject from the hit-info and from there the script component.

So assuming a script CubeScript on your cubes:

 var canUse = true; // change in inspector as needed

 // ... more stuff

... your raycasting script can do:

 var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
 var hit : RaycastHit;
 if (Physics.Raycast (ray, hit, 100)) {
     var go = hit.transform.gameObject;
     if (go.tag == "Foo") { // some test for hitting cubes
         var cubeScript = go.GetComponent(CubeScript);
         if (cubeScript && cubeScript.canUse) {
             // do stuff
         }
     }
 }
Comment
Add comment · Show 3 · 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 IMTRIGGERHAPPY9 · Oct 31, 2011 at 04:47 AM 0
Share

but will the first script's variable be only on that one object and then i can dynamically change the true and false of individual objects?

avatar image syclamoth · Oct 31, 2011 at 04:49 AM 1
Share

That's always the case- you need to specifically mark a variable 'static' to make it work in any other way!

avatar image gfr · Nov 01, 2011 at 04:12 AM 0
Share

Try to edit it into your question?

Also, try to figure out via logging when & why exactly the values are changed for the other objects. It's a bit hard to guess at what's going wrong with only seeing one part of the whole thing.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Lego-building System. 1 Answer

How to set a Transform variable with code (C#) 3 Answers

Grid matching issue 0 Answers

What is wrong with my code? 1 Answer

Adding Imperfections? 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