Hi guys, I have a question in picking up items and showing the count in GUIText, I have created some “Sticks” to pick up and a Stick Counter, I also added a sphere collider under “Sticks” to be picked up at a certain distance. I added the tag “Stick” for the sticks, and a script as below:
private var stick : int = 0;
var StickCounter : GUIText;
private var player : GameObject;
function OnTriggerEnter (other : Collider) {
if(other.gameObject == player)
{
playerInRange = true;
}
if (this.tag == "Stick"){
stick += 1;
Destroy(gameObject,0);
}
}
function Update () {
}
function OnGUI ()
{
StickCounter.text = stick.ToString();
}
The “Stick” disappeared when I passed through it but the GuiText number counter doesn’t change, I’m not sure why it’s not working, I’m thinking maybe because of Collider thing…Would someone please help? I totally have no idea how to fix this, Big Thanks!
have you checked to see what the value of ‘stick’ is to ensure that the variable is changing.
that way you know if the collisions are working, then you can focus on why its not showing in the GUI.
to test your variable, add a debug.log between lines 12 and 13, then the variable will show in the console window for you to check.
also have a look to see if you have set the reference to your GUIText gameobject. i take it you have dragged into the slot in the inspector if thats the way your referencing it?
is this script attached to the Stick object?
just wondering, as if its just needing to check if the player has collided, im not seeing a reason for checking the tag of the stick, if this is the only object where this script will be attached.
just check if other collider is the player, then do all the stuff. points, destroy etc…