I’m a beginner with Unity3d and I am using javascript.
I want to have Mobile input (Android or IOS) to trigger events in my Unity on my laptop. Is this possible? And how can I achieve it?
I was thinking about to press a button on the smart-phone so it sends a message to the unity program and triggers an event.
So as I understand this, you want to have two Unity applications running, one on the laptop and one on the smartphone. The smartphone application takes input from the user (and presumably has some sort of GUI), and sends the input in some serialized format to the application running on the laptop.
It sounds like you want to do all the logic on the laptop, rather than doing the logic on the smartphone and directly calling methods on the laptop. Unity provides the touches from the user as a struct, but unfortunately these are read only values - you can’t create a Touch yourself on the laptop.
One option is to create your own Touch struct that has the same fields as the built-in Touch struct but is read/write - perhaps call it MyTouch. Then, rather than having your code act off of Input.touches, you create an array of your MyTouch struct and use myTouches instead. The rest of your code would then be written as if you were getting the touches directly from the laptop.
Alternatively, there are third party tools that will deal with touch fakery. One we’ve used in the past is UniTUIO Community Edition.
Either way, your strategy would be to have an Update() function on the smartphone that looks for input. You would then serialize and send this input to the laptop (via RPC, a backend like SmartFox, or directly with sockets). The laptop would turn these messages into fake input, and from there everything would run as if it were a smartphone.
Good luck.