Version: 2022.3
言語: 日本語
public void SendMessageUpwards (string methodName, object value= null, SendMessageOptions options= SendMessageOptions.RequireReceiver);

パラメーター

methodName 呼び出すメソッドの名前
value 呼び出すメソッドに渡す値
options ターゲットのオブジェクトにメソッドが存在しない場合、エラーを発生させるかどうか

説明

Calls the method named methodName on every MonoBehaviour in this GameObject and on every ancestor of the behaviour.

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

このメッセージは非アクティブのゲームオブジェクトには送信されないことに気をつけてください(例えば、エディターのインスペクターや SetActive によって非アクティブにしている場合です)

using UnityEngine;

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

public class Example2 : MonoBehaviour { public void ApplyDamage(float damage) { print(damage); } }