• 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 user-5369 (google) · Oct 09, 2010 at 07:32 PM · collisionplayermessagecoinsend

Trouble sending message...

I'm trying to send a message from a coin prefab to a score gui to add 1 to the score everytime my player collides with a coin. Here's the coin script:

function OnTriggerEnter(other : Collider) { if(other.gameObject.CompareTag("Player")){ other.gameObject.SendMessage("OnScore", null); destroy = true;

} }

Here's the score gui's script:

var score : int = 0; function OnScore(){ score+=1; } function OnGUI () { GUI.Label (Rect (10, 10, 100, 20), "SCORE: " + score);

}

Does anyone know what's wrong here?

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 user-5369 (google) · Oct 09, 2010 at 09:07 PM 0
Share

The error reposrt is saying that OnScore has no receiver..

avatar image Ray-Pendergraph · Oct 09, 2010 at 10:19 PM 0
Share

I am not able to run Unity where I am... is there a version of Send$$anonymous$$essage that takes just a method name? I cant remember. It might be getting confused thinking it should be looking for a method with one argument (that happens to be set to null in your case). Try that or add a bogus float to the method. I'm pretty sure reflection is used to look up the method name.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bampf · Oct 09, 2010 at 08:25 PM

The idea looks sound.

  • Make sure your player object has a collider and is assigned the tag "Player".
  • Make sure the coin collider is set to be a Trigger.

Use the debugger or put a Debug.Log line at the top of the OnTrigger function to make sure it is getting called. If it is, then the test for player tag is failing. If it isn't, then the problem is with getting the trigger to fire.

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 · Oct 10, 2010 at 12:53 AM

SendMessage "calls the method named methodName on every MonoBehaviour in this game object."

OnScore() won't be found unless it's on the Player object, and by the sounds of things it isn't.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Collision script 1 Answer

Player Character Health 2 Answers

Player Dies when Collide with enemy 2 Answers

Mesh separating from CharacterController 0 Answers

How to turn of collision for the player 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