Hey,
I’ve been coding sections of my website using visual studio for my ASP.net web pages using the code behind feature. I know you can call web functions in unity and send them info from unity, but is it possible to call a function that is in the code behind feature? All examples are for functions in a script tag in html and just curious since my feeble attempts have failed.
thanks for any response.
Functions in ASP.NET code behind files are executed on the server, but Unity can only call JavaScript code that is on the client, i.e. in the same web page displaying the web player or included in that page using tags. So, no, you can’t call code behind functions from Unity.
What are you trying to do exactly?
I have an idea for my website that I want to run with since I haven’t seen it before… but it requires a bit of info swapping between some asp and unity… basically things done in unity changes variables in the asp side.
Can Unity send info to a JavaScript function that in turn sends the received info to an asp function… like a hidden button click or something similar?
That’s possible but it’s going to be hacky and probably very brittle. Instead I think you should look into using ASP.NET Web Services, or ASMX files. There’s an excellent article about that very subject here, linked to from an older thread on this forum.
Thanks for the links… hopefully it works in a webplayer build and I may be in business.
I searched around for a way to do this before asking, but searches seem to have a way to show you everything you don’t want to see… always off by a key word or someone explains it in different ways so I usually find it hard to search for specifics … thanks again.
Don’t sweat it. But I should add that, while still a perfectly valid and supported solution, ASMX web services are sort of considered old school these days. I only mentioned them because your question suggested you’re more familiar with WebForms, as opposed to ASP.NET MVC. If you’re feeling adventurous then you might want to also look into the new Web API from Microsoft or even the open source, Mono-friendly Service Stack.
I know just enough web form and html/css to be dangerous… but always adventurous so I’ll check into those too. Always open to learning new things so looking into it now.