Version: 2019.4
public void BroadcastMessage (string methodName, object parameter= null, SendMessageOptions options= SendMessageOptions.RequireReceiver);
public void BroadcastMessage (string methodName, SendMessageOptions options);

パラメーター

methodName呼び出すメソッド名
parameter呼び出すメソッドに渡すオプショナルパラメーター(どのような値でも可)
options目的のオブジェクトに指定したメソッドが存在しない場合、エラーを発生させるかどうか

説明

ゲームオブジェクトまたは子オブジェクトにあるすべての MonoBehaviour を継承したクラスにある methodName 名のメソッドを呼び出します。

The receiving method can choose to ignore parameter by having zero arguments. if options is set to SendMessageOptions.RequireReceiver an error is printed when the message is not picked up by any component.

using UnityEngine;

public class Example : MonoBehaviour { void Start() { /// Calls the function ApplyDamage with a value of 5 BroadcastMessage("ApplyDamage", 5.0); }

// Every script attached to the game object and all its children // that has a ApplyDamage function will be called. void ApplyDamage(float damage) { print(damage); } }