- Home /
Script is not working help plz
i wrote a simple script which works on colision and showa the name of the pbject that Controller collided with but it is not working i am geeting the message of objects name on console but it is not showing on Gui plz can anyone tell me what i am doing wrong here is the code
#pragma strict
var Pos:Vector3;
public var Rname : String;
public var R_name : String;
var player :GameObject;
var activeChild : GameObject;
var showLOc : boolean;
var str : String;
function Start()
{
player = GameObject.FindWithTag("Player");
activeChild = transform.gameObject;
}
function OnTriggerEnter (hit : Collider)
{
// if(hit.gameObject.tag == "MainCamera")
Rname = hit.transform.name;
Debug.Log("name "+Rname );
}
function OnGUI ()
{
Debug.Log("on gui fnc "+Rname );
if(showLOc)
{
Pos = activeChild.transform.position;
GUI.Label (Rect(110,Screen.height-40,550,70), "Region:" + Pos.ToString());
GUI.Label (Rect(110,Screen.height-60,550,70), "Region:" + Rname);
str = null;
}
}
function Update ()
{
if (Input.GetKeyDown(KeyCode.C))
showLOc = !showLOc;
setlayer();
}
function setlayer()
{
for (var child : Transform in player.transform)
{
if(child.active)
activeChild = child.transform.gameObject;
}
}
Thanks AR
Are you remembering to press "C" first to toggle the GUI display? What does the setlayer() function do? Is any guidisplayed? And what's the purpose of the str variable? (which always appears to be null)
yup i remember to press c of course and Str is Null i forget to delet that Set layer is capturing the active child of my character controller as i have 3 cameras in it fr different purpose
and yup Debug is working in On Trigger function but not working in OnGui
and position is being printed in gui and just Region: but not the name of the object i am colliding with
and i do remember to check the is trigger box of my collider to but the Value in Rname is not wotking in On Gui function i dnt knw why