Heres my new script and when my player collects 70 energy and i get back to the cube the GUI doesnt shows.
var Bob : Transform;
var Player : Transform;
var cameraMove : Camera;
private var distance : float;
function Update ()
{
if(Bob)
distance = Vector3.Distance(Bob.position, transform.position);
}
function OnGUI ()
{
if (distance <= 5)
GUI.Button(Rect(200,180,510,120),"Hello Player! Will you pls collect 70 energy for me?");
QuestAccepted();
print("Player is near BOB");
}
function QuestAccepted()
{
if(PlayersEnergy.PlayerEnergy == 70)
{
if(distance <= 5)
GUI.Button(Rect(200,180,510,120),"Thank you!");
}
}
What you have here will always show the "Hello Player!…" button and will also show the "Thank you!" button when the players energy is equal to exactly 70. I imagine that you only want the "Hello Player!…" button to show when the player has less than 70 energy. Is it possible for the player to collect more than 70 energy? Have you checked that PlayersEnergy.PlayerEnergy is actually getting updated? Put a print inside the QuestAccepted function to determine if the first if condition is ever being met.
– cagezero