Hey,
got a little problem here
This is the situation:
- Player A Connects
- Player B Connects.
Player A sees Healthbars correct.
Player B only sees his own Healthbar (if game is running in built *.exe)
if Player Bâs game is running in UnityEditor, he doesnt suffer from the problems in exe build and everything works right.
my idea was to set references again OnNetworkPlayerJoin (I am using Tnet) with
but it didnt change things.
im confused, hope youâre not
var tno:TNObject;
var refToPlayer : Player_Status;
var adjustment : float= 2.3f;
var customSkin:GUISkin;
var worldPosition : Vector3= new Vector3();
var screenPosition : Vector3= new Vector3();
var myTransform : Transform;
var myCamera : Camera;
private var healthBarHeight : int= 5;
private var healthBarLeft : int= 110;
private var barTop : int= 1;
private var myStyle : GUIStyle= new GUIStyle();
var myCam : GameObject;
function Awake()
{
myTransform = transform;
}
function Start(){
tno=GetComponent(TNObject);
myCamera =Camera.main;
refToPlayer = GetComponent(Player_Status);
myCam = GameObject.FindGameObjectWithTag("MainCamera");
}
function OnNetworkPlayerJoin(p:Player){
//tno.Send("sendHealthBar",p,myCamera,refToPlayer,myCam);
//sendHealthBar(myCamera,refToPlayer,myCam);
}
function OnGUI()
{
if(customSkin)
GUI.skin=customSkin;
worldPosition = new Vector3(myTransform.position.x, myTransform.position.y + adjustment,myTransform.position.z);
screenPosition = myCamera.WorldToScreenPoint(worldPosition);
//creating a ray that will travel forward from the camera's position
var ray = new Ray (myCam.transform.position, transform.forward);
var hit : RaycastHit;
var forward = transform.TransformDirection(Vector3.forward);
var distance = Vector3.Distance(myCam.transform.position, transform.position); //gets the distance between the camera, and the intended target we want to raycast to
//if something obstructs our raycast, that is if our characters are no longer 'visible,' dont draw their health on the screen.
if (!Physics.Raycast(ray, hit, distance))
{
GUI.color = Color.red;
GUI.HorizontalScrollbar(Rect (screenPosition.x - healthBarLeft / 2, Screen.height - screenPosition.y - barTop, 100, 0), 0, refToPlayer.health, 0, refToPlayer.maxHealth); //displays a healthbar
GUI.color = Color.white;
GUI.Label(Rect (screenPosition.x - healthBarLeft / 2, Screen.height - screenPosition.y - barTop-15, 400, 100), "myCam: "+myCam+" myCamera: "+myCamera);
GUI.contentColor = Color.white;
GUI.Label(Rect(screenPosition.x - healthBarLeft / 2+30, Screen.height - screenPosition.y - barTop-2, 100, 100), ""+refToPlayer.health.ToString("0")+"/"+refToPlayer.maxHealth); //displays health in text format
}
}
@RFC
function sendHealthBar(camera_:Camera,refToPlayer_:Player_Status,myCam_:GameObject )
{
myCamera = Camera.main;
refToPlayer = refToPlayer_;
myCam = GameObject.FindGameObjectWithTag("MainCamera");
}