Trying to fix my int to bool conflict

Im trying to get it so when i “spawn fish” it checks my UI text that shows the money to see if there is enough money for the “fish price” but “coin amount seems to be a bool? even though its showing integers?”

public class FishSpawner : MonoBehaviour
{
   
    public Vector3 center;
    public Vector3 size;
    public GameObject Fishprefab;
    public int fishPrice;
   
    // Start is called before the first frame update
    void Start()
    {

        SpawnFish();
        SpawnFish();
    }

    // Update is called once per frame
     public void Update()
    {
        Debug.Log(ScoreTextScript.coinAmount);
        if (Input.GetKeyDown(KeyCode.Q))
        SpawnFish();
    }

    public void SpawnFish()
       
    {//was working on this trying to get it to talk to the UI
        if (ScoreTextScript.coinAmount =+ fishPrice);
        Vector3 pos = center + new Vector3(Random.Range(-size.x / 2, size.x / 2), Random.Range(-size.y / 2, size.y / 2), Random.Range(-size.z / 2, size.z / 2));
            Instantiate(Fishprefab, pos, Quaternion.identity);
public class ScoreTextScript : MonoBehaviour
{
    Text text;
    public static int coinAmount;

    private void Start()
    {
        text = GetComponent<Text>();
    }

    public void Update()
    {
        text.text = coinAmount.ToString();
    }
}

Are you getting an error?

ah yeah my bad at 28,13 says that it “cannot be using both a int and a bool” but it thought it was all int’s?

This line looks wrong. What do you want it to do?

I basically want it to check my canvas text “coinAmount” and see if “fishPrice” is equal to or more then what is stated if so then spawn fish

if (ScoreTextScript.coinAmount =+ fishPrice);
        Vector3 pos = center + new Vector3(Random.Range(-size.x / 2, size.x / 2), Random.Range(-size.y / 2, size.y / 2), Random.Range(-size.z / 2, size.z / 2));
            Instantiate(Fishprefab, pos, Quaternion.identity);

for one thing, greater-than-or-equal-to is “>=” rather than “=+”. Here is a reference for comparison operators:
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/comparison-operators

Secondly, an if statement should actually not end with a semicolon “;”

Another thing- You have two statements that you want to happen if your conditoon is true. You need to put the statements between curly brackets “{” “}”

1 Like

Awesome fixes it thanks!