Scripting Error CS0029

I am brand new to this and following a tutorial where I’ve input the text exactly as the tutorial did but am getting this error instead of it working. Curious if anyone can tell me what I may need to do differently?

Error: Assets\LogicScript.cs(15,21): error CS0029: Cannot implicitly convert type ‘int’ to ‘UnityEngine.UI.Text’

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class LogicScript : MonoBehaviour
{
    public int playerScore;
    public Text scoreText;

    [ContextMenu("Increase Score")]
    public void AddScore()
    {
        playerScore = playerScore ++;
        scoreText = playerScore.ToString(); 
    }

}

Then you didn’t follow the tutorial! Go back and check your work over, you’re missing an important step.

Most likely you are missing something on that line where the error is (line 15).

Two steps to tutorials and / or example code:

  1. do them perfectly, to the letter (zero typos, including punctuation and capitalization)
  2. stop and understand each step to understand what is going on.

If you go past anything that you don’t understand, then you’re just mimicking what you saw without actually learning, essentially wasting your own time. It’s only two steps. Don’t skip either step.

Here’s more reading:

Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

The complete error message contains everything you need to know to fix the error yourself.

The important parts of the error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
  • the file it occurred in (critical!)
  • the line number and character position (the two numbers in parentheses)
  • also possibly useful is the stack trace (all the lines of text in the lower console window)

Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly? Are you structuring the syntax correctly? Look for examples!

All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.

1 Like

There are two errors in you script:

The first is in line 15 as the message says. It should be scoreText.text = playerScore.ToString();

The second is a logical error in line 14: The playerScore = playerScore ++; doesn’t make sense, it probably should be playerScore++;

If this wasn’t how it was written in the tutorial (which it shouldn’t be, if it was it’s a bad tutorial) you should try to be more careful when copying code, as things can be worse from a compiler error like in line 15 and be a logical error like in line 14 which will trouble you a lot, as the program won’t behave as expected.

If you ever feel tired by a tutorial you should stop and get some rest, because a simple logical mistake in code that won’t get caught by the compiler, can mean not only that you lost the time you used for the tutorial, but probably you will loose a few hours after that, trying to find out why the program doesn’t behave as expected.

1 Like

Here is an updated code.

   public void AddScore()
    {
        playerScore++;
        scoreText.text = playerScore.ToString();
    }