- Home /
Question by
TommyTheProgrammer · Dec 27, 2018 at 12:43 AM ·
gameobjectmessaging
Broadcast Message Not Working
Hi everyone, I have a problem with broadcasting message. Even when I put in the receiver script in its' child, unity still tells me "BroadcastMessage has no Receiver!" error, so my scripts don't work as well.
Here is my code on the parent:
public void SetPlayerName(InputField playername)
{
this.playername = playername.text; //this.playername is where I store the name data
BroadcastMessage("SendName", this.playername, SendMessageOptions.RequireReceiver);
}
Here is my receiver code in the child script:
void SendName(string playername)
{
this.playername = playername;//this.playername is another string variable where I store my playername data in the child
}
And I'm sure I put the receiver gameobject as the broadcaster's child.
(Tank is the parent, and PlayerInfos is the child). Can anyone help me with that?
helpme-unity1.png
(1.7 kB)
Comment
Best Answer
Answer by ray2yar · Dec 27, 2018 at 02:37 AM
I don't think you need the "this" everywhere. Also, try making your function public.
public InputField playerName;
void SetPlayerName()
{
//called when the inputfield has been modifed from the UI
BroadcastMessage("SendName", playerName.text,SendMessageOptions.DontRequireReceiver);
}
//function on children
public void SendName(string name)
{
//do stuff
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612184626im_/https://answers.unity.com/themes/thub/images/avi.jpg)