I'm new to both Unity3D and OPC UA. My task is to write a simple Android app by Unity, which can connect to an available OPC UA Server.
Actually I found some source on the Internet, e.g:
Create a very simple OPC client in Unity3d with opc ua .net library
The problem is, I don't really understand how the project work. I mean, for example, I create a connect Button and a text which indicate variable value. Then where to add the code? I tried some ways but it didn't work probably.
So can you give me some instruction? Thank you so much!
P/S: Here is my project: https://drive.google.com/file/d/1aQUoCXd6INWb7NcsOAR6h0lRWbhiPiog/view?usp=sharing
The OPC UA Code doesn't work (compile error but it have successfully built). Please take a look and let me know if you find my fault. Thank you

- 13
- 5
-
IMHO you should start at the beginning. How to create a unity application. How does OPC UA works. Step-by-step. You will realize that this is a learning curve. Walk before you run. You can't build a house in a day. – Jeroen van Langen May 12 '20 at 11:24
-
hi @JeroenvanLangen, I have editted my question, please review and give me some advice if possible. Thank you for replying to me. – mononaro May 13 '20 at 13:43
2 Answers
It could work for me with Android apk and also the windows platform. You can contact me if you still have some problems with it.
-
1Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 22 '21 at 19:06
First of all, Unity has a lot of documentation ready for you to get information out of, the documentation for a UI button can be found here: https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/script-Button.html
In that documentation you can see the OnClick event that triggers a UnityEvent.
A simple way to get your case working can be done simply by doing the following:
Create an empty gameobject
Assign a class (script) that you made to this gameobject
Add a public method that does your connecting, or just do a print for now so you can see what happens, Unity has a print(string) method :)
To make sure it is working, you can also put a print in the start method (called at the start of a scene).
You can then click on + of the OnClick method, seen in this
image of the documentation.
Select the gameobject with the script, select the script and then the method you created. Run and press the button.

- 1
- 1
-
Hi Jan Julius. First of all, thank you for replying to me. I'm sorry for not being clear, but my problem is writing and adding C# code (about OPC UA), not the button click event. I mean, I copied code in the link above, add it to C# script named "TestOPC.cs", then add the script to my GameObject. When I click Play, the code is supposed to intiallize OPC UA connection between my Unity app and OPC UA Server. However, there's alway a message like "all compiler errors have to be fixed before you can enter playmode", but I cannot find out that error(notthing in Console,my code is sucessfully built) – mononaro May 13 '20 at 12:13
-
If you are able to instruct me sth about OPC UA in Unity, please let me know so that I could send you my project for more details. Thank you so much – mononaro May 13 '20 at 12:14