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");
}
Answer by Tjovo-studios · Apr 08, 2021 at 10:48 AM
SendMessage ("ApplyConsumedEffectHealth");
So it works at me. And then:
void ApplyConsumedEffectHealth(){
//Do something
}
Your answer
Follow this Question
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