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);

Parámetros

methodNameNombre del método a llamar.
valueParámetro opcional para el método.
optionsDebería un error lanzarse si el objeto destino no implementa el método para el mensaje?

Descripción

Llama al método denominado methodName en cada MonoBehaviour de este 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.

Tenga en cuenta que los mensajes no se enviarán a objetos inactivos (es decir, aquellos que se hayan desactivado en el editor o con la función 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); } }