// gets instructions from the statement blocks and sends them to this array.
let log = [];
// cycles through the array and gives instructions to unity
function animater() {
var action = log.shift();
if (action === "FORWARD") {
unityGame.SendMessage("single boat(Clone)", "StartCoroutine", "MoveForward");
}
if (action === "LEFT") {
unityGame.SendMessage("single boat(Clone)", "StartCoroutine", "TurnLeft");
}
if (action === "RIGHT") {
unityGame.SendMessage("single boat(Clone)", "StartCoroutine", "TurnRight");
}
if (action === "BACKWARD") {
unityGame.SendMessage("single boat(Clone)", "StartCoroutine", "MoveBackward");
}
if (log.length) setTimeout(animater, 2200);
}
I have a button under my workspace that calls the animater function. I had an issue when the function was called animate so I changed it to animater.
My move blocks simply create code that sends strings like "FORWARD" and "LEFT" to the log array above. When the user clicks "run", the code gets generated sending the strings to the log array. The user then clicks the "animater" button that calls the animator function.
Try that and see how you get on.