Open happyturtle5 opened 9 years ago
You can modify the controller by changing Assets/WebPlayerTemplates/HappyFunTimes/controller.html
and Assets/WebPlayerTemplates/HappyFunTimes/controller.js
to whatever you want them to be.
Some details are here.
Basically you make messages in some script in Unity and get a "NetPlayer" object. For the HFTGamepad you can get its net player object like this
using HappyFunTimes;
private HFTGamepad m_gamepad;
private NetPlayer m_netPlayer;
void Start()
{
m_gamepad = GetComponent<HFTGamepad>();
m_netPlayer = m_gamepad.NetPlayer;
}
Then you either send messages from the game (unity) to the controller (javascript) or from the controller back to the game.
In your case you probably just want to send single string like this
private class MessageShowMessage : MessageCmdData
{
MessageShowMessage(string _msg)
{
msg = _msg;
}
public string msg;
}
And you can send it to the controller like this
m_netPlayer.SendCmd("showmsg", new MessageShowMessage("Hello world!");
In controller.js you might have some code like this to receive the message
client.addEventListener('showmsg", handleShowMessage);
function handleShowMessage(data) {
msgElement.innerHTML = data.msg;
}
Of course you need to add some HTML to controller.html to have a place to display the message
<div id="msg"></div>
And in controller.js you'd need to look that up
var msgElement = document.getElementById("msg");
You'd probably also need some CSS to position the message in Assets/WebPlayerTemplates/HappyFunTimes/css/controller.css
something like
#msg {
position: absolute;
left: 10px;
top: 10xp;
}
That's just a guess of course. How you want to display the message is up to you. Maybe you want lots of fancy CSS. Maybe you want to send the CSS from Unity. Maybe you want to pass a color from Unity. Maybe you want to pass time to show it from unity. All of that is up to your game and ideas.
And yes you can test by opening a local browser. Just open a browser window and go to http://localhost:18679
.
Ok thanks! I'll have a look at the next game jam!
I tried to ask a question on stackoverflow using the "happyfuntimes" tag. But since the tag seems not to be used yet, I can create no question with this tag. (You need a certain reputation to create an own tag for questions.)
My question is: How can I modify the preset controller?
I am using the 2D sample project of happyfuntimes and would like to display the player's score directly on their phone.
Which script do I use to accomplish this? HFTGamepad.cs? controller.js? PhonePlayerScript?
Can I test the controller without connecting a phone to the game? E.g. by opening a browser?