What is the best approach for building your character input system on top of NGUI, then sending commands from NGUI buttons and widgets to your own player over the network?
Would you want to create the UI like most other network objects at the game start?
Is it necessary to have your controller script send your own players commands over the network, or is it best to just send the results from that input command to the rest of the room?
What is the best way to reference and send commands to your own player?
Currently, I have it working pretty well like this, but I want to understand if this is the right approach.
My input handler script attached to an NGUI widget that lives in the scene :
var myPlayer : GameObject;
function Start () {
}
function OnClick () {
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
Debug.Log("click");
if (Physics.Raycast (ray, hit, 100)) {
if (hit.collider.gameObject.layer == 9) {
var targetPoint = hit.point;
var myTno = myPlayer.GetComponent(TNObject);
myTno.Send("OnSetTarget", TNet.Target.AllSaved, targetPoint);
}
}
}
My character controller script :
#pragma strict
var targetPos : Vector3;
var tno : TNObject;
var myController : TouchHandler;
function Start () {
tno = gameObject.GetComponent.<TNObject>();
targetPos = transform.position;
if (tno.isMine) {
myController = GameObject.Find("LookArea").GetComponent(TouchHandler);
myController.myPlayer = gameObject;
}
}
@TNet.RFC
function OnSetTarget (tar) {
transform.position = tar;
}