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

スクリプト言語

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

GameObject.SendMessageUpwards

フィードバック

ありがとうございます

この度はドキュメントの品質向上のためにご意見・ご要望をお寄せいただき、誠にありがとうございます。頂いた内容をドキュメントチームで確認し、必要に応じて修正を致します。

閉じる

送信に失敗しました

なんらかのエラーが発生したため送信が出来ませんでした。しばらく経ってから<a>もう一度送信</a>してください。ドキュメントの品質向上のために時間を割いて頂き誠にありがとうございます。

閉じる

キャンセル

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

パラメーター

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

説明

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

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

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

	// Calls the function ApplyDamage with a value of 5
	gameObject.SendMessageUpwards ("ApplyDamage", 5.0);
	
	// Every script attached to the game object 
	// that has an ApplyDamage function will be called.
	function ApplyDamage (damage : float) {
		print (damage);
	}
using UnityEngine;
using System.Collections;

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