- Home /
error CS0029: Cannot implicitly convert type 'string' to 'int'... I EVEN ADDED .ToString();
HELP ME!
HEY IM GETTING THIS ERROR Assets\CoinCounter.cs(20,25): error CS0029: Cannot implicitly convert type 'string' to 'int'
using UnityEngine; using UnityEngine.UI;
public class CoinCounter : MonoBehaviour { public GameObject Coin; public Text NumberOfCoins; public int DefaultZero = 0; public int CoinValue = 1;
void Update (Collision collisionInfo)
{
if (collisionInfo.collider.tag == "Char")
{
Coin.SetActive(false);
NumberOfCoins.text = DefaultZero += CoinValue.ToString(); //ERROR HERE
}
}
}
Comment
Answer by pako · Nov 24, 2020 at 06:20 PM
You must perform the addition (+=) before converting to string, otherwise, you're trying to add the string CoinValue.ToString()
to the int DefaultZero
So try: NumberOfCoins.text = (DefaultZero += CoinValue).ToString();