0

I added a GUI text GameObject to a new project and attached a new C# script to it.

I want the GUI text GameObject to count up to 10000 (increment by 1 every frame) and stop when it reaches 10000. I used a for loop to try and achieve this, but I get the following error:

Assets/oText.cs(20,33): error CS0029: Cannot implicitly convert type 'int' to 'string'

What am I doing wrong?

My C# script is:

using UnityEngine;
using System.Collections;

public class oText : MonoBehaviour {

    // Use this for initialization
    void Start () {
        guiText.text = "GUI Text Area Test";

    }
    
    // Update is called once per frame
    void Update () {
        int myInt = 1;

        for(int i = 0; i < 10000; i++)
        {
            myInt = myInt + 1;
            guiText.text = myInt;
        }
    }
}

1 Answer 1

3

guiText.text is a string. myInt is an int. The conversion isn't implicit. You need to specify an explicit conversion:

guiText.text = myInt.ToString();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.