Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by ReggieBeRetro · Aug 29, 2016 at 09:56 PM · sendmessage

SendMessage Not working

Im confused why im getting this SendMessage ApplyConsumedEffectHealth has no receiver! SendMessage ApplyConsumedEffectStamina has no receiver! SendMessage ApplyConsumedEffectThirst has no receiver! SendMessage ApplyConsumedEffectHunger has no receiver!

ive read many forums and cant find a solution if i dont want to instantiate a temp object at the time when i need a send message sent. I tried with a empty game object and quickly destroying it and i get the same thing. i have also tried to Find a random game object by tags instantiating it then a send message and it work. BUT! i then have a object in the scene when i dont want it there.

Here is my code that sends the message.

 if (item.itemModel.tag == "Food") {
 
 
 
 
                 PlayerEffects = GameObject.Find ("RigidBodyFPSController").GetComponent<PlayerGUI> ();
                 if (item.itemAttributes [0].attributeName == "Health") {
 
 
 
                     effects = item.itemAttributes [0].attributeValue * 0.10f;
                     SendMessage ("ApplyConsumedEffectHealth", effects, SendMessageOptions.RequireReceiver);
                     
                 } 
 
 
                 if (item.itemAttributes [2].attributeName == "Stamina") {
 
 
 
                     effects = item.itemAttributes [2].attributeValue * 0.10f;
                     SendMessage ("ApplyConsumedEffectStamina", effects, SendMessageOptions.RequireReceiver);
                     
                 }
 
 
                 if (item.itemAttributes [1].attributeName == "Thirst") {
                     
                 
 
                     effects = item.itemAttributes [0].attributeValue * 0.10f;
                     SendMessage ("ApplyConsumedEffectThirst", effects, SendMessageOptions.RequireReceiver);
                     
                 
                     
                 }
                 if (item.itemAttributes [3].attributeName == "Hunger") {
                     
 
 
                     effects = item.itemAttributes [0].attributeValue * 0.10f;
                     SendMessage ("ApplyConsumedEffectHunger", effects, SendMessageOptions.RequireReceiver);
                     
                 
                 }
                 
 
             }

Then here is my code that receives it.

 void ApplyConsumedEffectHealth(float effects) {
         if (currentHealth >= 1) {
             currentHealth = 1;
             healthBarDisplay = currentHealth;
         } else {
             if (effects > 0) {
                 currentHealth = effects;
                 healthBarDisplay += currentHealth;
             }
             else
             {
                 currentHealth = effects;
                 healthBarDisplay -= currentHealth;
             }
         }
         Debug.Log ("health applied");
 
 
     }
     void ApplyConsumedEffectStamina(float effects) {
         if (currentStamina >= 1) {
             currentStamina = 1;
             staminaBarDisplay = currentStamina;
         } else {
             if (effects > 0) {
             currentStamina = effects;
             staminaBarDisplay += currentStamina;
             } 
             else 
             {
                 currentStamina = effects;
                 staminaBarDisplay -= currentStamina;
             }
         }
         Debug.Log ("stamina applied");
 
 
     }
     void ApplyConsumedEffectHunger(float effects) {
         if (currentHunger >= 1) {
             currentHunger = 1;
             hungerBarDisplay = currentHunger;
         } else {
             if (effects > 0) {
                 currentHunger = effects;
                 hungerBarDisplay += currentHunger;
             }
             else
             {
                 currentHunger = effects;
                 hungerBarDisplay -= currentHunger;
             }
         }
         Debug.Log ("hunger applied");
     
 
     }
     void ApplyConsumedEffectThirst(float effects) {
         if (currentThirst >= 1) {
             currentThirst = 1;
             thirstBarDisplay = currentThirst;
         } else {
             if (effects > 0) {
                 currentThirst = effects;
                 thirstBarDisplay += currentThirst;
             } else {
                 currentThirst = effects;
                 thirstBarDisplay -= currentThirst;
             }
         }
         Debug.Log ("thirst applied");
 
 
     }
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

· Add your reply
  • Sort: 
avatar image
0

Answer by Tjovo-studios · Apr 08, 2021 at 10:48 AM

 SendMessage ("ApplyConsumedEffectHealth");

So it works at me. And then:

 void ApplyConsumedEffectHealth(){
 //Do something
 }


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

67 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Recive Message 0 Answers

Trouble with virtual and protected 2 Answers

Passing String Array in UnityPlayer.UnitySendMessage 0 Answers

Alert All Enemies Inside Certain Area 1 Answer

SendMessage function not working 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