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
3
Question by Mike Ledwards · Dec 27, 2010 at 09:01 PM · tagmessageammosend

How to Send Message to other GameObject

how do you SendMessage to another object?

i am trying to send addAmmo from a box on collider enter with the Player,

for some reason i can only recieve the message on scripts attached to the player i want to go to my Gun.

var ammo = 20;

function OnTriggerEnter (collision : Collider) {

if (collision.gameObject.FindWithTag ("Player"))
SendMessage("addAmmo",ammo,SendMessageOptions.DontRequireReceiver);
    Debug.Log("sent");
    DestroyObject (gameObject);
}

i get the Debug |Log so its workin'...

function addAmmo (ammo : float) {

Ammo += ammo;
Debug.Log("PickUP");

}

however this dosent.

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
Best Answer

Answer by Matthew A · Jan 01, 2011 at 02:48 PM

Do you mean that the message is sent only to the Player object, and you need it to propagate down the object hierarchy to your gun object???

If so, you want to use BroadcastMessage instead of SendMessage (with the same parameters).

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
1

Answer by The_r0nin · Dec 27, 2010 at 09:07 PM

Put this on the ammo box (in a collision check):

collision.gameObject.SendMessage("addAmmo",ammo,SendMessageOptions.DontRequireReceiver);
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 Mike Ledwards · Dec 27, 2010 at 09:10 PM 0
Share

if you read above that is what ive done however it is in the receiver where i have the problem

avatar image
1

Answer by heks · Dec 27, 2010 at 11:41 PM

Since you're assigning an integer to your ammo variable I suspect the addAmmo() function should take an integer as well (instead of float):

function addAmmo (ammo : int) {
    Ammo += ammo;
    Debug.Log("PickUP");
}

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

SendMessage , how can i send two parameter 3 Answers

BroadcastMessage 1 Answer

Flame Thrower - Particle Collision Help 1 Answer

Pass Enum To Function Parameter 2 Answers

How do i Specify a Receiver for a Send Message Function? 2 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