if(shouldSelectPlanet)
{
//other code that works without this if statement
}
and my problem is that it doesn’t want to work.
When I run the game with out this if statement it works. (not how its suppose to but it does)
but when I run the game with this if statement it doesn’t work at all.
I have tried it like this:
if(shouldSelectPlanet == true)
{
//other code that works without this if statement
}
but this still does not work.
in a bit of script further down that enabled shouldSelectPlanet, underneath that line I have a print statement to check if it IS being changed to TRUE. And it is. Although, it still does not work. I HAVE checked over every possible script for any change it makes and theres nothing. I am really confused and any help would be appreciated thanks!
Hmmm, the if statement is inside the Update() function. Also the only code that could possibly cancel it out is inside the if statement at the part that would mean it works. So its really confusing as to why it isn’t working
Here is the if statement and its guts WITH the function thats called when a button is clicked
void Update()
{
print(shouldSelectPlanet);
if (shouldSelectPlanet) //Is always false for some odd reason
{
//Here down WORKS if the above if statement is commented out or deleted
if (Input.GetMouseButtonDown(0)) //Click the left mouse button
{
Ray ray = Camera.main.GetComponent<Camera>().ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity))
{
if (check == 0)
{
switch (hit.transform.tag)
{
case "Player":
GameManager.news = "You can not destroy your own planet!";
break;
case "Stray":
selectedPlanet = hit.transform.gameObject;
GameManager.news = "Click this planet again to verify you wish to destroy it!";
check++;
break;
case "Enemy":
selectedPlanet = hit.transform.gameObject;
GameManager.news = "Click this planet again to verify you wish to destroy it!";
check++;
break;
default:
GameManager.news = "Please select a planet to destroy!";
break;
}
}
else if (check == 1 && hit.transform == selectedPlanet.transform)
{
LaunchRocketAtPlanet();
check = 0;
}
else
{
check = 0;
GameManager.news = "Please select a planet to destroy!";
}
}
}
}
}
//Function Called When a UGUI button is clicked
public void StartProcess()
{
if (PlayerUnits.missiles >= 1)
{
if (!GameManager.isBuilding && !GameManager.isUpgrading && !GameManager.isCreatingUnits && !GameManager.isResearching)
{
shouldSelectPlanet = true;
GameManager.news = "Please select a planet to destroy!";
//Stop ALL processes
GameManager.isLaunchingMissile = true;
}
}
else
{
CreateMissile();
}
}
Or you paste your code here and get help
I know why I wrote that you should post the complete code. It is not that unlikely that you have made your boolean a public field that can be modified in the inspector. You may initialize it in the script to a certain value when you declare it, but that doesn’t count when you have it in the inspector.
Your issue is that your using a bool so it needs to be true or false or it’s nothing and won’t read. So in your case if has to be if(shouldSelectPlanet == false)
or (ifShouldSelectPlanet == true)
This won’t give you errors cause it’s not wrong it’s just not doing anything.
Hope that helps./
Try switching around the code to have the input first. Then run the if(shouldSelctPlanet == true or false)
I know I made a building system with a similar issue and it was just switching around the if statements,
If that doesn’t work then try if input.getkeydown && shouldselectplanet == true.
if (shouldSelectPlanet)
{
Debug.Log("I'm here 1");
if (Input.GetMouseButtonDown(0))
{
Debug.Log("I'm here 2");
Ray ray = Camera.main.GetComponent<Camera>().ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity))
{
Debug.Log("I'm here 3");
if (check == 0)
{
Debug.Log("I'm here 4");
switch (hit.transform.tag)
{
can you just addd some debug logs and see how far it get’s ?
maybe its entering the frist if but doesn’t go further