Component.SendMessage Manual     Reference     Scripting  
Scripting > Runtime Classes > Component
Component.SendMessage
このドキュメントは有志により翻訳されたもので、オフィシャルではありません。オリジナルのページはこちら
This document is unofficially translated by users.Please see the original document here.

翻訳に関する修正など、ご連絡はこちらまで。
Please send e-mail to here, when you have any question about the translation.

編集 (GitHub)

function SendMessage (methodName : string, value : object = null, options : SendMessageOptions = SendMessageOptions.RequireReceiver) : void

Description

Calls the method named methodName on every MonoBehaviour in this game object.

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.

JavaScripts
// 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.
function ApplyDamage (damage : float) {
print (damage);
}

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
void ApplyDamage(float damage) {
print(damage);
}
public void Awake() {
SendMessage("ApplyDamage", 5.0F);
}
}

import UnityEngine
import System.Collections

class example(MonoBehaviour):

def ApplyDamage(damage as single):
print(damage)

public def Awake():
SendMessage('ApplyDamage', 5.0F)