Dialog system bugs?

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.

1 Answer

1

function OnGUI() {

		if (distance <= 5) {
			
			print("Player is near BOB");
			
			if(PlayersEnergy.PlayerEnergy >= 70)
				GUI.Button(Rect(200,180,510,120),"Thank you!");
			else
				GUI.Button(Rect(200,180,510,120),"Hello Player! Will you pls collect 70 energy for me?");
		}
}

Glad to help! If this answer has solved your issue please consider marking it as the correct answer.