Sender

From Unify Community Wiki
Revision as of 16:15, 7 February 2007 by Jeffcraighead (Talk | contribs)

Jump to: navigation, search

Sender Script

A sender sends data via a Server. This script was implemented so that the code could be modified in one place. It sends the root object name, the name of the object it's attached to, and whatever is passed in as the data variable. A script could simply access the Server directly and bypass the Sender.

Code

<javascript> private var server : Server = null;

function Start(){ var controller = GameObject.FindWithTag("GameController"); if(controller!=null)server = controller.GetComponent("Server"); }

function Send(data){ if(server==null) { var controller = GameObject.FindWithTag("GameController"); if(controller!=null)server = controller.GetComponent("Server"); } if(server!=null && server.Connected()){ var sendString = gameObject.transform.root.name + "," + gameObject.name + "," + data + "\n"; server.PutMessage(sendString); } } </javascript>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox