给Yuka中的Vehicle对象发送消息。
vehicle.sendMessage( receiver, message )
Object
,接收消息的目标对象。Object
,消息内容。无返回值。
const vehicleB = new YUKA.Vehicle();
const vehicleC = new YUKA.Vehicle();
const message = { foo: 'bar' };
vehicleB.onMessage = function( sender, message ) {
console.log( 'VehicleB has received a message from VehicleA:', message );
};
vehicleC.onMessage = function( sender, message ) {
console.log( 'VehicleC has received a message from VehicleA:', message );
};
vehicleA.sendMessage( vehicleB, message );
vehicleA.sendMessage( vehicleC, message );
如果receiver或message参数未提供或不合法,将抛出TypeError异常。