- Home /
Question by
PizzaPablo666 · Aug 18, 2017 at 11:36 AM ·
errorstring
Operator '==' can't be applied by operands Text and String
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameController : MonoBehaviour {
public Text[] buttonList;
private string playerSide;
void Awake()
{
SetGameControllerReferenceOnButtons();
playerSide = "X";
}
void SetGameControllerReferenceOnButtons()
{
for (int i = 0; i < buttonList.Length; i++)
{
buttonList[i].GetComponentInParent<Buttons>().SetGameControllerReference(this);
}
}
public string GetPlayerSide()
{
return playerSide;
}
public void EndTurn()
{
if (buttonList[0].text == playerSide && buttonList[1] == playerSide && buttonList[2].text == playerSide)
{
GameOver();
}
}
void GameOver()
{
for (int i = 0; i < buttonList.Length; i++)
{
buttonList[i].GetComponentInParent<Button>().interactable = false;
}
}
}
Error is Operator '==' cannot be applied to operands of type 'UnityEngine.UI.Text' and 'string' , please help to fix this
Comment
Best Answer
Answer by Bodhid · Aug 18, 2017 at 11:54 AM
You forgot to add .text
after buttonList[1] at line 31
Answer by Benster1599 · Aug 18, 2017 at 01:59 PM
line 31: if (buttonList[0].text == playerSide && buttonList[1].text == playerSide && buttonList[2].text == playerSide)
Your answer
![](https://koobas.hobune.stream/wayback/20220612133012im_/https://answers.unity.com/themes/thub/images/avi.jpg)