Publish :
using UnityEngine;
using System.Collections;
public class PublisherBall : MonoBehaviour {
public delegate void BallEventHandler(string s);
public event BallEventHandler BallDropEvent;
public string s;
void Start () {
BallDropEvent += MethodHandleEventForPublisher;
}
void Update () {
}
void OnCollisionEnter(Collision c)
{
if (BallDropEvent != null)
{
BallDropEvent(s);
}
}
void MethodHandleEventForPublisher(string s)
{
s = this.s;
Debug.Log (s);
}
}
Receive:
using UnityEngine;
using System.Collections;
public class ReceiverBall : MonoBehaviour {
public GameObject publisherBall;
public string s;
public float jumpForce;
void Start () {
publisherBall.GetComponent<PublisherBall> ().BallDropEvent += MethodHandleEvent;
}
void Update () {
}
void MethodHandleEvent(string s){
s = this.s;
Debug.Log (s);
GetComponent<Rigidbody> ().AddForce (new Vector3 (0f, jumpForce, 0f));
}
}