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
1
Question by Sam 5 · Mar 03, 2011 at 03:39 AM · multiple

Is it possible to get two scripts from different objects to talk to each other without assigning objects in the inspector?

Ok, for reference I'm doing a spaceship game in Boo. I have a ship, it is parent to a camera and an empty that acts as an anchor point for a weapon of the player's choice. Each of these potential weapons has a script that needs a variable from a script running on the camera.

Now in my 1st prototype the anchor point empty was actually the weapon itself and was fixed, unchanging. As such I could use:

public Targetscript as Targeting1
public Gpos as Vector3
def update():
    Gpos = Targetscript.GunneryPOS

where Targeting1 is the name of the script attached to the camera, and GunneryPOS is the variable I need to pull. Drag and drop the camera to Targeting1 in the inspector and everything was happy. Now however, with swapping out weapons and possibly having multiple ships I feel like the drag and drop to the inspector is not particularly flexible.

I feel like the answer I'm looking for has something to do with transform.root and/or transform.Find(). I want to say "Hey weapon, you are now part of a ship. Go look for the camera that's also part of the ship and pull GunneryPOS from Targeting1." I'm just not sure quite how.

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 Peter G · Mar 03, 2011 at 03:45 AM 0
Share

Wow, someone who writes in Boo, +1 for that.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by by0log1c · Mar 03, 2011 at 04:16 AM

I'm more familiar with JS but I've used Unity scripting reference to write it in BOO(quite similar after,all?) after reading Peter's comment, here's an example:

//for a specific instance on a specific GameObject: Targetscript = GameObject.Find('theGameObjectName').GetComponent[of Targeting1]();

//or : Targetscript = FindObjectOfType(Targeting1); Targetscripts = FindObjectsOfType(Targeting1); //also works

AFAIK, .Find and .GetComponent are considered slow only if used repeatedly. The idea is to store the result in a variable like the example above.

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

No one has followed this question yet.

Related Questions

Accessing Booleans from other scripts 0 Answers

get same var from multiple different scripts 1 Answer

Is it standard practice for game items to run multiple scripts? 1 Answer

foreach script check if boolean is true 3 Answers

Using a Variable over two Scripts 4 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