お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
ClosemethodName | 呼び出すメソッドの名前 |
value | 呼び出すメソッドに渡す値 |
options | ターゲットのオブジェクトにメソッドが存在しない場合、エラーを発生させるかどうか |
ゲームオブジェクトにアタッチされている全てのMonoBehaviourにある methodName
と名付けたメソッドを呼び出します
メソッドの実行時に引数の数を0にすることによって渡される引数の値を無視することが出来ます。 /options/ が SendMessageOptions.RequireReceiver に設定した場合、コンポーネントに該当するメソッドが存在しない場合はエラーが発生します。 このメッセージは非アクティブのゲームオブジェクトには送信されないことに気をつけてください(例えば、エディタのインスペクターや SetActive によって非アクティブにしている場合です)
// Calls the function ApplyDamage with a value of 5 gameObject.SendMessage ("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.SendMessage("ApplyDamage", 5.0F); } }
import UnityEngine import System.Collections public class ExampleClass(MonoBehaviour): def ApplyDamage(damage as float) as void: print(damage) def Example() as void: gameObject.SendMessage('ApplyDamage', 5.0F)