error CS0019: Operator '<' cannot be applied to operands of type 'string' and 'int'
I tried some ways to fix this, but this is an error yet. Can anyone help me?
public GameObject Xvreli = null;
public int zPos;
public int enemyCount;
void Start()
{
StartCoroutine(EnemyDrop());
}
IEnumerator EnemyDrop()
{
while (Xvreli.name < 5)
{
zPos = Random.Range(0, 1000);
Instantiate(Xvreli, new Vector3(0, 0, zPos), Quaternion.identity);
yield return new WaitForSeconds(0.3f);
Xvreli.name += 2;
}
}
Well the error is quite self-explanatory..
It looks like what you wanted to do is parsing the name value to an int value and back e.g. using int.Parse
int nameInt;
while((nameInt = int.Parse(Xvreli.name)) < 5)
{
...
Xvreli.name = (nameInt + 2).ToString();
}
or also int.TryParse (doesn't throw format exception)
while (int.TryParse(Xvreli.name, out var nameInt) && nameInt < 5)
{
...
Xvreli.name = (nameInt + 2).ToString();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With