Skip to content

Instantly share code, notes, and snippets.

@bitchwhocodes
Last active August 29, 2015 14:04
Show Gist options
  • Save bitchwhocodes/a99a26580b8659e76a6a to your computer and use it in GitHub Desktop.
Save bitchwhocodes/a99a26580b8659e76a6a to your computer and use it in GitHub Desktop.
Unity3d and Spacebrew - Script for button ( SendButton.cs)
using UnityEngine;
using System.Collections;
public class SendButton : MonoBehaviour {
// Use this for initialization
SpacebrewClient sbClient;
// Use this for initialization
// Get a referece to the Spacebrew Object
void Start () {
// Need reference to object so we can publish from a button click.
GameObject go = GameObject.Find ("SpacebrewObject"); // the name of your client object
sbClient = go.GetComponent<SpacebrewClient>();
}
// We can inspect the _msg object to deterine what type of message etc. We handle data received here.
public void OnSpacebrewEvent(SpacebrewClient.SpacebrewMessage _msg)
{
GameObject.Find("subscribeText").guiText.text = _msg.value;
}
// When we click the button, we will send a message that will include the name of the button pressed.
void OnMouseDown() {
sbClient.sendMessage("button_pressed", "string", this.gameObject.transform.name);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment