Last active
August 29, 2015 14:04
-
-
Save bitchwhocodes/a99a26580b8659e76a6a to your computer and use it in GitHub Desktop.
Unity3d and Spacebrew - Script for button ( SendButton.cs)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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