In the above script I wanted pick-up apples with my player with OnCollisionEnter. This part works fine. Nevertheless, I found a problem when I try to pass the picked-up apples to the GUI interface because the collected apples do not register the won points on GUI. That is, the GUI line: carriedGui.text = "Carrying: " + carrying + " of " + carryLimit; shows on the screen without progress of the variable carrying (the picked-up apples). But if I watch this script on the Inspector, the field Carrying DOES register the apples (points). Any help, please!
var carrying : int;
var carryLimit : int;
var deposited : int;
var winScore : int;
var appleCollect : AudioClip;
var carriedGui : GUIText;
var depositedGui : GUIText;
private var timeSinceLastPlay : float;
public function Start()
{
timeSinceLastPlay = Time.time;
UpdateCarryingGui();
UpdateDepositedGui();
}
function UpdateCarryingGui()
{
carriedGui.text = "Carrying: " + carrying + " of " + carryLimit;
}
function UpdateDepositedGui()
{
depositedGui.text = "Deposited: " + deposited + " of " + winScore;
}
function OnTriggerEnter(collisionInfo : Collider)
{
if(collisionInfo.gameObject.tag == "apple")
{
carrying++;
audio.PlayOneShot(appleCollect);
Destroy(collisionInfo.gameObject);
}
}
Do you mean putting carrying inside the function UpdateCarryingGui()? I did that but, it does not work. In fact, with this modification, on the Inspector appears one point on the start, which is worst than in the previous case.
– pepefirst