I’ve been going over this problem for last hour and yet to figure out why my buttons aren’t coming up and hopefully someone out there can see something obvious I’m missing.
I have other buttons in my script that all work fine. E.g. I have a Input.GetMouseButtonDown(1) event that is triggered and sets a bool value sowSelect to true and the next piece of code in my OnGUI().
if(sowSelect){
//if statement runs if button clicked, displays wheat image and paints selected tile with type 2
if (GUI.Button(new Rect(button.x, button.y, 50, 50), wheatButton, blankbg)){
if(randomTilePainter){ // if true paint 5 tile type
//check to see if this tile has a crop object assigned to it
if(tile.assignedCrop == null){
tile.assignedCrop = new Wheat(Time.time);
terrain.PaintTile1x1(tile, 5); //asigned it a seedling image.
moneyCoutner.GetComponent<MoneyDisplay>().takeFunds(tile.assignedCrop.getCost()); // take whatever the cost is from the object
}//end assigned crop
randomTilePainter = false; //swap tile painter
}else if(!randomTilePainter){//if false paint 6 tile type.
//check to see if this tile has a crop object assigned to it
if(tile.assignedCrop == null){
tile.assignedCrop = new Wheat(Time.time);
terrain.PaintTile1x1(tile, 6);
moneyCoutner.GetComponent<MoneyDisplay>().takeFunds(tile.assignedCrop.getCost());
}//end tile null.
}//end randomtile if
sowSelect = false;
}//end wheatbutton if
Now this code works fine and buttons display on click, but on virtually the same code that on mouse down sets bool value harvestAble to true the follow code happens:
//if harvestable has been set, show buttons.
if(harvestAble){
//check what type is ready for harvest - SWITCH may be better by giving each crop an id, 0 wheat, 1 corn etc.
if(tile.assignedCrop.getType() == "Wheat"){
print("tiel if" + tile.assignedCrop.getType());
//show button for wheat harvest
if(GUI.Button(new Rect(button.x, button.y, 50, 50), wheatHarvestButton, blankbg)){
tile.assignedCrop.harvest(Time.time);
}//end wheatbutton if
}else if(tile.assignedCrop.getType() == "Corn"){ //if it is corn
print("tile if" + tile.assignedCrop.getType());
//show corn harvest button
if(GUI.Button(new Rect(button.x, button.y, 50, 50), cornHarvestButton, blankbg)){
tile.assignedCrop.harvest(Time.time);
}//end wheatbutton if
//else if users has already selected harvest for this grid, show selected already so not to reharvest.
}else if(tile.assignedCrop.getHarvesting()){
if(GUI.Button(new Rect(button.x, button.y, 50, 50), "This crop is already being harvested!")){
}//end harvested button if
}//end gettype if
harvestAble = false; // Stop it trying to reharvest item
}//end harvestable if
Now the print functions I put in the if statement to check if the mouse click event is activated and goes into code just before the button if and it displays that tile if and also lists that it does have a type and it is correct, but no button. I’ve even copied by button code from the sowSelect which worked and still nothing. I’ve even set the new Rect(250,250,50,50) just to see if stating where to place it helped, but noavail and I’m out of ideas so if anyone can help I’d be in your debt.