Version: 5.3 (switch to 5.4b)
言語English
  • C#
  • JS

スクリプト言語

好きな言語を選択してください。選択した言語でスクリプトコードが表示されます。

Component.SendMessageUpwards

マニュアルに切り替える
public void SendMessageUpwards(string methodName, object value = null, SendMessageOptions options = SendMessageOptions.RequireReceiver);
public void SendMessageUpwards(string methodName, object value = null, SendMessageOptions options = SendMessageOptions.RequireReceiver);
public void SendMessageUpwards(string methodName, SendMessageOptions options);
public void SendMessageUpwards(string methodName, object value = null, SendMessageOptions options = SendMessageOptions.RequireReceiver);

パラメーター

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

説明

ゲームオブジェクトと親(の親、さらに親 ... )にアタッチされているすべての MonoBehaviour にある methodName と名付けたメソッドを呼び出します

メソッドの実行時に引数の数を 0 にすることによって渡される引数の値を無視することができます。 options パラメーターに、SendMessageOptions.RequireReceiver を設定した場合、該当するコンポーネントが存在しない場合はエラーメッセージが発生します。

このメッセージは非アクティブのオブジェクトには送信されないことに気をつけてください(すなわち、エディターや GameObject.SetActive 関数で非アクティブにしている場合です)

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void ApplyDamage(float damage) { print(damage); } void Example() { SendMessageUpwards("ApplyDamage", 5.0F); } }