Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

questions on stackoverflow #11

Open
happyturtle5 opened this issue Aug 22, 2015 · 2 comments
Open

questions on stackoverflow #11

happyturtle5 opened this issue Aug 22, 2015 · 2 comments

Comments

@happyturtle5
Copy link

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?

@greggman
Copy link
Owner

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.

@happyturtle5
Copy link
Author

Ok thanks! I'll have a look at the next game jam!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants