Help please

I keep getting this error kind of like this

Assets/UpgradeManager.cs(21,19): error CS0266: Cannot implicitly convert type float' to int’. An explicit conversion exists (are you missing a cast?)

I don’t really get the problem here, doesn’t seem like theres anything wrong.

using UnityEngine;

public class UpgradeManager : MonoBehaviour {

    public Click click;
    public UnityEngine.UI.Text itemInfo;
    public float cost;
    public int count = 0;
    public int clickPower;
    public string itemName;
    private float _newCost;

    void Update() {
        itemInfo.text = itemName + "\nCost: " + cost + "\nPower: +" + clickPower;

    }

    public void PurchasedUpgrade() {
        if (click.cookie >= cost) {
            click.cookie -= cost;
            count += 1;
            click.cookieperclick += clickPower;
            cost = Mathf.Round(cost * 1.15f);
            _newCost = Mathf.Pow(cost, _newCost = cost);

        }

    }


}

The click.cookie -= cost; is apparently wrong
Thanks

well cost is a float, so I assume “Click.cookie” is an int. The “Cannot implicitly convert” means the compiler doesn’t know if you want to change the int to a float, or the float to an int… so it’s waiting to be told, i.e. an explicit cast

Alright. Thanks Lefty hehe

To expand on that - the compiler will implicitly cast when the casted value does not result in a loss of data. An int can implicitly cast to a float because a float contains “more data” (ie decimal values) than an int does. You can’t go from a float to an int because you would lose that decimal information so the compiler needs to be told how you want that cast to happen (round up, round down, truncate, etc).

What would I change?

without knowing too much about what you’re doing… either cast the int to a float, or change Click.cookie to a float type.

by virtue of the fact that you’re costs aren’t whole number integer values, I’d probably go with the “currency” (I’m assuming that’s what Click.cookie is?) being a float too.

Sorry for being a bad rookie but how would I change click.cookie into a float type?