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 07, 2018 at 08:13 AM by Myth for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Myth · Jul 24, 2012 at 12:35 AM · javascriptcollisionparentprojectile

Finding a script on an object

Hi,

I have the following code which works, but I was wondering how it could be modified to find the DamageReceiver script if it was on the parent of the object that the projectile hit.

e.g.

I shoot the spaceship - I can find the script

I shoot the shield - I cannot – but is there a way I could?

 function OnCollisionEnter( collision : Collision )
 {
  // find out where and what we hit
  var contact : ContactPoint = collision.contacts[0];
  var rotation = Quaternion.FromToRotation( Vector3.up, contact.normal );
  // visual effects
  var instantiatedExplosion : GameObject = Instantiate(explosion, contact.point, transform.rotation);
  // tell the other object that they have been hit and how badly
  if (contact.otherCollider.GetComponent(DamageReceiver))
  {
  contact.otherCollider.GetComponent(DamageReceiver).attacked = true;
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

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by DaveA · Jul 24, 2012 at 12:48 AM

You might instead want to use SendMessageUpwards http://docs.unity3d.com/Documentation/ScriptReference/GameObject.SendMessageUpwards.html which will send the message also to the parent(s)

Comment
Add comment · Show 4 · 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 Myth · Jul 24, 2012 at 12:50 AM 0
Share

I decided against this due the the amount of information I need to send.

I also could not get it to send a javascript object containing the information to be accessed by the receiving script

avatar image DaveA · Jul 24, 2012 at 08:15 PM 1
Share

Are you sure? That API takes type 'object' so it should take anything I would think, structs or classes.

You can also crawl the tree yourself by accessing otherCollider.transform.parent and going up that.

avatar image Myth · Jul 25, 2012 at 03:19 AM 0
Share

it was sending but the content was unacessable on the other end. I will try the tree crawl thing, but if you could give me a working example of sending and retrieving data using an object that would be great.

avatar image Myth · Jul 25, 2012 at 10:57 PM 0
Share

Solved using the crawl mentioned above

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Update Parent/ Children From Script? 2 Answers

Changing the parent of an object in a script 2 Answers

Character falls through the ground 1 Answer

GUI.Box within a Collider 1 Answer

i cant get an object to become child of an other JS 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