Call to unity from OnClick not working. #271
Unanswered
Attackonteentitans
asked this question in
Help Wanted!
Replies: 1 comment 6 replies
-
Hi. Could you send a little more code? I'm interested in the part where you declare the Unity Context. Depending on your implementation, you might break its reference to the Unity Application. |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
WHen my program executes this code to interact from React to Unity it does nothing because the this.unityInstance is null. Why would this be since the unity application is running. My application runs, and is now sending data to my react app, but when I try to call a method back again it fails due to this problem. I have tried everything, How do I fix it?
UnityContext.prototype.send = function (gameObjectName, methodName, parameter) {
if (this.unityInstance !== null) {
if (parameter === undefined) {
this.unityInstance.SendMessage(gameObjectName, methodName);
}
Seems to work ifcI immediately call a UNITY method from the same method I receive a message from unity in but not when I make a call from onclick:
This works to call back..
useState(function () {
unityContext.on("NextPlayer", function (gridString) {
setGridString(gridString);
if (playerNbr === 1)
{
playerNbr = 2;
unityContext.send("Player2Spawner", "nextPlayer", gridString);
}
else {
playerNbr = 1;
unityContext.send("Player1Spawner", "nextPlayer", gridString);
}
Beta Was this translation helpful? Give feedback.
All reactions