Version: 2022.3
言語: 日本語
public void SendMessage (string methodName);
public void SendMessage (string methodName, object value);
public void SendMessage (string methodName, object value, SendMessageOptions options);
public void SendMessage (string methodName, SendMessageOptions options);

パラメーター

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

説明

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

The receiving method can choose to ignore the argument 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.

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

using UnityEngine;

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

// Every script attached to the game object // that has a ApplyDamage function will be called. void ApplyDamage(float damage) { print(damage); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961