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 PJ Belcher · Jan 28, 2011 at 06:04 PM · sendmessagecommunicationfov

Communicating between objects without any physical connection?

I'm trying to find a way to send a message from one object to another without them having any physical interaction. There are no collisions, no projectiles, and they are not parented in any way?

What would be the best way to do this?

What I'm trying to achieve is a system whereby I can tell if something is within my camera's Field of View. And then whether that object is or isn't effect it's behavior accordingly.

Any help much appreciated. Thanks!

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by PrimeDerektive · Jan 28, 2011 at 08:35 PM

var allObjects = Object.FindObjectsOfType(GameObject);

for (var go : GameObject in allObjects){ if (go.renderer.isVisible){ // if this gameobject is visible by any camera go.GetComponent(MyScript).DoStuff(); } }

Note that you could of course use FindObjectsWithTag or FindObjectsOfType(MyScript) or any other method of specifying what type of objects you actually want this functionality to be restricted to. Finding ALL the objects in the scene might get a little intense depending on what you have going on.

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 Jessy · Jan 28, 2011 at 06:24 PM

http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html

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 zharramadar · Jan 28, 2011 at 07:33 PM

Find the object with GameObject.Find() and then use GameObject.SendMessage() to call a method in this object you want. This will call the specified method in any script attached to the GameObject you found. For example:

GameObject obj = GameObject.Find("player"); obj.SendMessage("Hit");

This will find the object named player and execute any or all methods called Hit in any script attached to the player gameobject.

If you want to simply manipulate the gameobject you found, just use the methods in the variable obj (in the case of the example above)

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 Jessy · Jan 28, 2011 at 07:53 PM 0
Share

I do not support suggesting Send$$anonymous$$assage for what you described. Your example is in C#, so $$anonymous$$ono's event handling would be appropriate.

avatar image PrimeDerektive · Jan 28, 2011 at 08:30 PM 0
Share

Indeed, Send$$anonymous$$assage might make the object too relaxed.

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

Communication issue from Browser to Web Player 2 Answers

SendMessage throwing "No appropriate version of 'UnityEngine.GameObject.SendMessage' 1 Answer

Browser to unity communication 2 Answers

sendMessage from Flash to Unity 1 Answer

Allowing communication with the device on local network 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