Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Return data from Unity script to browser.

Discussion in 'Web' started by godszerg86, Feb 21, 2019.

  1. godszerg86

    godszerg86

    Joined:
    Dec 19, 2018
    Posts:
    10
    Greetings,

    I have a WebGL project, also I have some front-end code. When I click the button on the front end inside browser I want to collect some player data and send it back to the front end so I can manipulate with it in my JavaScript.

    Is there any way for Unity script return data to front end?
    For example something like this:

    Code (CSharp):
    1. public string HelloWorld()
    2. {
    3. return "HelloWorld";
    4. }
    and on front end smth like that:
    Code (JavaScript):
    1. let helloString = gameInstance.SendMessage("GameObject", "HelloWorld")
    Or if I want to notify browser that Unity completed WebRequest or failed.
     
  2. Schubkraft

    Schubkraft

    Unity Technologies

    Joined:
    Dec 3, 2012
    Posts:
    1,070
  3. godszerg86

    godszerg86

    Joined:
    Dec 19, 2018
    Posts:
    10
    Thank you, but I read that article before I asked.
    Let me be more explicit.
    I have a front end with VueJS which will be minified on the build. So I can't call my external JS functions.
    I don't want to create global variables attached to the window object.
    I want to SendMessage or smth like that from Vue and get back the result.
     
  4. Schubkraft

    Schubkraft

    Unity Technologies

    Joined:
    Dec 3, 2012
    Posts:
    1,070
    There is only the way described in the manual, sorry.
     
  5. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
    Depends on the vars that you want to get, you can share specific cells from the heap buffer.
    It can be used for floats or ints