Home:ALL Converter>When TEXT is SOMETHING then do THAT - Unity 2D

When TEXT is SOMETHING then do THAT - Unity 2D

Ask Time:2021-09-22T05:56:05         Author:Wiktor Wdowiak

Json Formatter

I wanted to do the thing, when Text equals "Cherries: 12" then do GameJolt.API.Trophies.Unlock(******);

The problem is, when I do this:

if(Text.Equals = "Cherries: 12")
        {
            GameJolt.API.Trophies.Unlock(******);
        }

It says Cannot assign to 'Equals' because it is a 'method group' Also, I'm new to programming, so if I did anything wrong here, please inform me!

Can someone help me please?

Author:Wiktor Wdowiak,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/69275959/when-text-is-something-then-do-that-unity-2d
TEEBQNE :

What type is Text? Is it of type UnityEngine.UI.Text? Or is it of type string? The reason you are getting the error Cannot assign to 'Equals' because it is a 'method group' is because you are calling the method Equals and attempting to assign the value "Cherries: 12" to it.\nInstead of using the assignment operator =, you want to use a comparison operator ==. It will compare to values. However, as you are already using Equals, you do not need any sort of comparison, you can simply pass in the value to the method.\nIf your Text is a UI object, the code should look like:\nif(Text.text.Equals("Cherries: 12"))\n{\n GameJolt.API.Trophies.Unlock(******);\n}\n\nHowever, if the Text is a string object, the code should look like:\nif(Text.Equals("Cherries: 12"))\n{\n GameJolt.API.Trophies.Unlock(******);\n}\n\nAlternatively, you can use the comparison operator without needing to use the Equals method.\nif(Text == "Cherries: 12")\n{\n GameJolt.API.Trophies.Unlock(******);\n}\n",
2021-09-21T22:03:40
yy