From 174ac285f4fd2616135592f9b3417e1aa1d028dd Mon Sep 17 00:00:00 2001 From: Varun Barad Date: Sat, 21 Dec 2024 14:59:58 +0530 Subject: [PATCH] Listen to messages coming from unity. --- sim/api.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sim/api.ts b/sim/api.ts index a44cca6f..61c5a972 100644 --- a/sim/api.ts +++ b/sim/api.ts @@ -30,6 +30,13 @@ namespace pxsim.unity { //% blockId=helloUnity block="helloUnity" export function helloUnity() { + window.addEventListener('message', (event) => { + const command = event.data.unityCommand; + const data = event.data.unityData; + if (!!command) { + console.log(`Received command ${command} from unity with data: ${data}`); + } + }); if (!window.parent) { console.log('MakeCode: Parent not found'); } else {